Is there a way to stop shiny from freezing/"greying out" R plots updating live every x seconds

2,471 views
Skip to first unread message

Claymore Marshall

unread,
Aug 15, 2014, 10:54:31 AM8/15/14
to shiny-...@googlegroups.com
I have an app that plots live data (stock prices in this example) every x seconds.

My problem is that when the plots being updated depend on reactive values or expressions that take considerable time to compute (i.e. more than a second), the plots (observers) "grey out" during this calculation period, which is unappealing to look at.

Attached is a simple example to demonstrate the problem (with a screen shot too).  The bottom plot updates the way I would expect, but the top plot does not.  The top plot has the right dependence structure, but the plot greys out for as long as the computation in 'values' takes.  The bottom plot is sort of a 'work around'. The bottom plot updates every x seconds the way I want live plots to update, but the problem with the bottom panel is that it does not necessarily update AFTER 'values' (which could be an intensive data computation) has updated, also every x seconds.

Is there, by any slim chance, a way to 'turn off' the 'greying out' feature of plots in shiny which are updating after a change in one of the shiny inputs change?


server.R
ui.R
Screenshot from 2014-08-15 10:51:49.png

David Eubanks

unread,
Aug 16, 2014, 7:53:03 AM8/16/14
to shiny-...@googlegroups.com
See if this helps. 

########### server.R

library(shiny)
library(quantmod)

data <- getSymbols('AAPL')
shinyServer(function(input, output, session) {

  # create a reactive variable
  rvals <- reactiveValues(dataReady = 0)
  
  values <- reactive({
    
    invalidateLater(input$delay * 1000, session)
    Sys.sleep(2) # This sleep represents some intensive calculation that takes a few seconds to crunch through
    startbar <- sample(1:1000,1)
    
    # done with computations, ready to plot, so trigger a reactive variable
    # the rval must be in isolate() to avoid an infinite loop!
    # it is scoped so that we don't need the <<- assignment
    isolate(rvals$dataReady <- rvals$dataReady + 1) 
    
    res <<- AAPL[startbar:(startbar + 250),]
    res  
  })  
    
  output$distPlot <- renderPlot({
    y <- values() # need this for updating in plot to work... 
    chart_Series(res)
  })
  
  output$distPlot2 <- renderPlot({
    #invalidateLater(input$delay * 1000, session)
    rvals$dataReady #set dependency
    chart_Series(res)
  })

})

Claymore Marshall

unread,
Aug 18, 2014, 11:02:19 AM8/18/14
to shiny-...@googlegroups.com
Thanks for the suggestion.

Unfortunately this still does not resolve the plot that depends on values from freezing/"greying out"....

Clay

unread,
Oct 6, 2015, 1:24:02 PM10/6/15
to Shiny - Web Framework for R
In case anyone else has this issue, here is a solution that prevents greying out of plots or tables.

Just after fluidPage in ui.R, adding this line:

tags$style(type="text/css",
        ".recalculating {opacity: 1.0;}"
    ),

Infinite Flash Chess

unread,
Jun 1, 2016, 4:11:20 PM6/1/16
to Shiny - Web Framework for R
This worked for me, thanks! This was simple, short and straight to the point. 
Reply all
Reply to author
Forward
0 new messages