ComeçarComece de graça

Reactivity: simple reactive variable

In reactive programming, an expression gets re-evaluated whenever any of its dependencies are modified. In Shiny, all inputs are reactive variables. This means that any time the user manipulates an input control to change its value, any code block that depends on that variable (such as a render function) reacts to the input variable's new value by re-evaluating.

You can also create new reactive variables with the reactive() function.

The following code defines a reactive variable called my_sum that calculates the sum of two numeric inputs named num1 and num2.

my_sum <- reactive({
  input$num1 + input$num2
})

When does the my_sum variable get re-computed?

Este exercício faz parte do curso

Case Studies: Building Web Applications with Shiny in R

Ver curso

Exercício interativo prático

Transforme a teoria em ação com um de nossos exercícios interativos

Começar o exercício