3.4 Laziness

It allows apps to be extremely lazy:

  • Shiny’s aim is to only do the work that is needed.
  • It will only update outputs that you can currently see.

3.4.1 Will this app work?

library(shiny)

ui <- fluidPage(
  textInput("name", "What is your name?"),
  textOutput("greeting"),
  textOutput("nice_day")
)

server <- function(input, output, session) {
  output$greeting <- renderText(str_c("Hello ", input$name, "!"))
  
  output$nic_day <- renderText(str_c("Have a nice day, ", input$name, "!"))
}

shinyApp(ui, server)

CAUTION: If you’re working on a Shiny app and you just can’t figure out why your code never gets run, double check that your UI and server functions are using the same identifiers.