Created
January 28, 2014 18:08
-
-
Save ptoche/8672980 to your computer and use it in GitHub Desktop.
Demo on dynamic number of sliders
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
# server.R | |
shinyServer(function(input, output, session) { | |
output$sliders <- renderUI({ | |
if (is.null(input$n) || is.na(input$n)) { | |
n <- 1 | |
} else { | |
n <- round(input$n,0) | |
} | |
lapply(1:n, function(i) { | |
sliderInput( | |
inputId = paste0("sliderId", i) | |
, label = paste0("Slider", i) | |
, min = 0 | |
, max = 10 | |
, value = c(0, 2) | |
, step = 1 | |
) | |
}) | |
}) | |
}) |
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
# ui.R | |
shinyUI( | |
basicPage( | |
numericInput(inputId = "n", label = "How many sliders to display?", value = 1) | |
, | |
uiOutput("sliders") | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment