Aan de slagGa gratis aan de slag

Reactivity: effects of isolation

If there is a reactive variable that appears multiple times in your code, and you want to ensure that its modification does not trigger a re-evaluation of the code, you need to isolate all the instances of that variable. That means that if a variable x is inside an isolate() but also appears outside of it, then it will trigger reactivity.

The following code defines a reactive variable result and calculates it using three input values:

result <- reactive({
  temp <- input$X + input$Y
  isolate({
    temp <- temp * input$Y * input$Z
  })
  temp
})

In the code above, when does the result reactive variable get updated?

Deze oefening maakt deel uit van de cursus

Case Studies: Building Web Applications with Shiny in R

Cursus bekijken

Praktische interactieve oefening

Zet theorie om in actie met een van onze interactieve oefeningen.

Begin met trainen