A reactive can be used to make output depend on another expression. In the example below, the output$text element is dependent on text_reactive, which in turn is dependent on input$user_text. Whenever input$user_text changes, output$text element and text_reactive become invalidated. They are recalculated based on the new value for input$user_text.
library(shiny)
ui <- fluidPage(
headerPanel("Example reactive"),
mainPanel(
# input field
textInput("user_text", label = "Enter some text:", placeholder = "Please enter some text."),
# display text output
textOutput("text"))
)
server <- function(input, output) {
# reactive expression
text_reactive <- reactive({
input$user_text
})
# text output
output$text <- renderText({
text_reactive()
})
}
shinyApp(ui = ui, server = server)