Last active
February 1, 2018 05:45
-
-
Save aagarw30/4ee5c09c3075c06fa8087cec951adb97 to your computer and use it in GitHub Desktop.
Demo - Dynamic Widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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