Skip to content

Instantly share code, notes, and snippets.

@xiaodaigh
Last active December 23, 2015 19:39
Show Gist options
  • Save xiaodaigh/6684134 to your computer and use it in GitHub Desktop.
Save xiaodaigh/6684134 to your computer and use it in GitHub Desktop.
Shiny: Multiple selections created using one htmlOutput

To run

shiny::runGist("6684134")

shinyServer(function(input, output, session) {
output$selectInputs <- renderUI({
print("w")
w <- ""
for(i in 1:input$obs) {
w <- paste(w,selectInput(paste("a",i,sep=""),paste("a",i,sep=""),choices=1:input$obs,selected=i))
}
HTML(w)
})
output$summary <- renderPrint({
print("your selections are:")
for(i in 1:input$obs) {
print(
input[[sprintf("a%d",i)]]
)
}
})
outputOptions(output, 'selectInputs', suspendWhenHidden=FALSE)
})
# Experimental Area ui shiny
shinyUI(basicPage(
verbatimTextOutput("summary"),
numericInput("obs", "how many selects:", 5,min = 1, max = 100)
,htmlOutput("selectInputs")
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment