shinyServer(function(input, output, session) {
# Anything that calls autoInvalidate will automatically invalidate
# every 2 seconds.
autoInvalidate <- reactiveTimer(2000, session)
observe({
# Invalidate and re-execute this reactive expression every time the
# timer fires.
autoInvalidate()
# Do something each time this is invalidated.
# The isolate() makes this observer _not_ get invalidated and re-executed
# when input$n changes.
print(paste("The value of input$n is", isolate(input$n)))
})
# Generate a new histogram each time the timer fires, but not when
# input$n changes.
output$plot <- renderPlot({
autoInvalidate()
hist(isolate(input$n))
})
})
Run the code above in your browser using DataLab