Matthias Ho
Matthias Ho

Reputation: 57

invalidateLater - Shiny

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

Upvotes: 1

Views: 497

Answers (1)

Gregor de Cillia
Gregor de Cillia

Reputation: 7645

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

Upvotes: 3

Related Questions