Skip to content

Instantly share code, notes, and snippets.

@ptoche
Created January 28, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptoche/8672980 to your computer and use it in GitHub Desktop.
Save ptoche/8672980 to your computer and use it in GitHub Desktop.
Demo on dynamic number of sliders
# 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
)
})
})
})
# 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