Reputation: 1190
Title says it all really, I'm trying to think of a way to do create multiple UI elements.
So if I have n number of elements in a selector (data sets) - Each of these data sets has differently named column names and of different lengths. I'd like these column names as group inputs.
I think I could do this statically, if I knew how many datasets there were going to be (such as the example below) - but is there a way I could generate the checkboxgroupinput iteratively for example?
ui.r
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Example"),
sidebarPanel(
checkboxGroupInput("one", "One:",data_in[[1]]),
checkboxGroupInput("two", "Two:",data_in[[2]]),
),
mainPanel(
)
))
Upvotes: 1
Views: 454
Reputation: 30425
Yes you can use renderUI
data_in <- c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")
library(shiny)
runApp(
list(ui = pageWithSidebar(
headerPanel("Example"),
sidebarPanel(
uiOutput("checkbGroups")
),
mainPanel(
)
)
,
server = function(input, output, session){
output$checkbGroups <- renderUI({
lapply(1:10, function(x){
do.call(checkboxGroupInput, list(inputId = x, label = x, choices = data_in))
}
)
}
)
}
)
)
Upvotes: 3