Get startedGet started for free

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?

This exercise is part of the course

Case Studies: Building Web Applications with Shiny in R

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise