Skip to content

Instantly share code, notes, and snippets.

@aagarw30
Last active February 1, 2018 05:45
Show Gist options
  • Save aagarw30/4ee5c09c3075c06fa8087cec951adb97 to your computer and use it in GitHub Desktop.
Save aagarw30/4ee5c09c3075c06fa8087cec951adb97 to your computer and use it in GitHub Desktop.
Demo - Dynamic Widgets
library(shiny)
ui <- basicPage(
fluidRow(
selectInput("num", "select number of slider inputs", choices = seq(1,5,1)),
uiOutput("sliders"),
tableOutput("table"),
tableOutput("sum")
))
server <- function(input, output){
output$sliders <- renderUI({
lapply(1:input$num, function(i) {
sliderInput(inputId = paste0("ind", i), label = paste("Individual", i),
min = 0, max = 5, value = 1)
})
})
output$table <- renderTable({
num <- as.integer(input$num)
data.frame(lapply(1:num, function(i) {
input[[paste0("ind", i)]]
}))
})
output$sum <- renderTable({
num <- as.integer(input$num)
dat <- data.frame(lapply(1:num, function(i) {
input[[paste0("ind", i)]]
}))
sum(dat)
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment