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)
})
})