[英]R/Shiny: Populate CheckBox Group Dynamically Using Headers From Uploaded File
I'm trying to build a page using R Shiny that has:我正在尝试使用 R Shiny 构建一个页面,该页面具有:
A File Widget for uploading CSV files用于上传 CSV 文件的文件小部件
A Checkbox Group component复选框组组件
I'd like to use these as follows:我想按如下方式使用这些:
I've tried various forms of observe() and observeEvent() so far, but have had no success in getting this even close.到目前为止,我已经尝试了各种形式的 observe() 和 observeEvent(),但都没有成功实现这一点。 Any suggestions you may have would be great.
您可能有任何建议都会很棒。
You may try checkboxGroupInput
.您可以尝试
checkboxGroupInput
。
library(shiny)
ui <- fluidPage(
fileInput('file', 'Upload csv file'),
uiOutput('dropdown')
)
server <- function(input, output) {
data <- reactive({
req(input$file)
read.csv(input$file$datapath)
})
output$dropdown <- renderUI({
req(data())
checkboxGroupInput('cols', 'Select Column', names(data()),
names(data()), inline = TRUE)
})
}
shinyApp(ui, server)
You can set inline = FALSE
if you want to arrange them vertically.如果要垂直排列它们,可以设置
inline = FALSE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.