Shiny reactivity :: examples
https://github.com/rstudio/shiny/tree/master/inst/examples/03_reactivity
ui.R | server.R |
fluidPage( titlePanel("Reactivity"), sidebarLayout( sidebarPanel( textInput("caption", "Caption:", "Data Summary"), selectInput("dataset", "Choose a dataset:", choices=c("rock","pressure","cars")), numericInput("obs", "No of obs to view:", 10) ), mainPanel( h3(textOutput("caption", container = span)), verbatimTextOutput("summary"), tableOutput("view") ) ) )
|
function(input, output, sessions){ datasetInput <- reactive({ switch(input$dataset, "rock" = rock, "pressure" = pressure, "cars" = cars) }) output$caption <- renderText({ input$caption }) output$summary <- renderPrint({ dataset <- datasetInput() summary(dataset) }) output$view <- renderTable({ head(datasetInput(), n = input$obs) }) }
|