问题
Is there any way to undo the invalidateLater function after it has been turn on?
You would agree that reactivity is not need all the time, maybe after certain hour, when grabbing of data is no longer needed. Any suggestion?
It is also officially documented that "It's possible to stop this cycle by adding conditional logic that prevents the invalidateLater from being run.", but I cannot find any example to understand how this work.
Thanks
回答1:
Here is a simple example on how to use "conditional logic" to prevent invalidateLater
from being run.
library(shiny)
shinyApp(
fluidPage(
checkboxInput('count', 'count up'),
verbatimTextOutput('text')
),
function(input, output, session){
counter <- reactiveVal(0)
observe({
if(!is.null(input$count))
if(input$count){
invalidateLater(500)
counter(isolate(counter())+1)
}
})
output$text <- renderText({
counter()
})
}
)
来源:https://stackoverflow.com/questions/47485981/invalidatelater-shiny