invalidateLater - Shiny

家住魔仙堡 提交于 2019-12-14 04:22:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!