Shiny reactivity :: examples

Published by onesixx on

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)
  })
}

 

 

 

Categories: Shiny

onesixx

Blog Owner

Leave a Reply

Your email address will not be published.