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: R-Shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x