1.5 Adding behaviour

Need server function to bring the outputs to life

Reactive programming tells Shiny how to perform a function.

It’s the difference between giving someone a recipe versus demanding that they go make you a sandwich. ~ Hadley Wickham (Author of Mastering Shiny)

Your coding the range of app behaviors, but the user of your app demands the output based on their selection of input(s).

This code tells shiny how to fill in the summary and table outputs we defined in the UI.

server <- function(input, output, session) {
  output$summary <- renderPrint({
    dataset <- get(input$dataset, "package:datasets")
    summary(dataset)
  })
  
  output$table <- renderTable({
    dataset <- get(input$dataset, "package:datasets")
    dataset
  })
}

Each output$out_id is a new shiny output to render where the UI defines it

There are specific render functions render{Type} for different outputs:

  • text
  • tables
  • plots
  • images
  • new ui components