[英]R shiny - Generating n number of UI Elements
Title says it all really, I'm trying to think of a way to do create multiple UI elements. 标题说明了一切,我正在试图想办法创建多个UI元素。
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. 因此,如果我在选择器中有n个元素(数据集) - 这些数据集中的每一个都具有不同的名称列名和不同的长度。 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? 我想我可以静态地做这个,如果我知道将会有多少数据集(例如下面的例子) - 但是有没有办法我可以迭代地生成checkboxgroupinput例如?
ui.r ui.r
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Example"),
sidebarPanel(
checkboxGroupInput("one", "One:",data_in[[1]]),
checkboxGroupInput("two", "Two:",data_in[[2]]),
),
mainPanel(
)
))
Yes you can use renderUI
是的,您可以使用
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))
}
)
}
)
}
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.