App 1: Module server

  1. Create a function with the ID argument.
  2. Call the shiny::moduleServer() and pass the id and a function that looks like a regular server function.

Note: Thanks to that id the shiny::moduleServer() will be able to bring the inputs and outputs created in the UI function.

histogramServer <- function(id) {
  moduleServer(id, function(input, output, session) {
    data <- reactive(mtcars[[input$var]])
    output$hist <- renderPlot({
      hist(data(), breaks = input$bins, main = input$var)
    }, res = 96)
  })
}