3.2 A deeper dive into the server function

server <- function(input, output, session)

  1. input
  • list-like object
  • used for receiving input (sent from the browser)
  • read-only (no x <- ‘12’ in server; otherwise you’ll get an error)
  • must be read in a reactive context (e.g. renderText() or reactive())
    • Otherwise, you’ll get an error.
  1. output
  • list-like object
  • used for sending output
  • ALWAYS use with a render fn() - sets up the reactive context & renders the HTML.
ui <- fluidPage(
  textInput("name", "What's your name?"),
  textOutput("greeting")
)

server <- function(input, output, session) {
  output$greeting <- renderText({
    paste0("Hello ", input$name, "!")
  })
}