R 使用上传文件中的数据创建多个闪亮的小部件
在R 使用上传文件中的数据创建多个闪亮的小部件,r,shiny,R,Shiny,在shinny中,如何在renderUI中使用tagList来创建多个小部件,这些小部件使用上传文件中的数据进行定制?这个想法被引用了,但是对于tagList,似乎没有很好的文档 我打算在这里回答我自己的问题。我做了一点研究,发现这个过程缺少一个简单的例子,我想贡献它,让其他人受益。在server.R中,使用reactive()语句定义一个对象来保存上传文件的内容。然后,在renderUI语句中,将小部件定义的逗号分隔列表包装到tagList函数中。在每个小部件中,使用保存上载文件内容的对象作为
shinny
中,如何在renderUI
中使用tagList
来创建多个小部件,这些小部件使用上传文件中的数据进行定制?这个想法被引用了,但是对于tagList
,似乎没有很好的文档
我打算在这里回答我自己的问题。我做了一点研究,发现这个过程缺少一个简单的例子,我想贡献它,让其他人受益。在server.R中,使用
reactive()
语句定义一个对象来保存上传文件的内容。然后,在renderUI
语句中,将小部件定义的逗号分隔列表包装到tagList
函数中。在每个小部件中,使用保存上载文件内容的对象作为小部件参数。下面的示例和使用基于上载文件定义的singer renderUI创建checkBoxGroupInput和radioButtons小部件
server.R
library(shiny)
shinyServer(function(input, output) {
ItemList = reactive(
if(is.null(input$CheckListFile)){return()
} else {d2 = read.csv(input$CheckListFile$datapath)
return(as.character(d2[,1]))}
)
output$CustomCheckList <- renderUI({
if(is.null(ItemList())){return ()
} else tagList(
checkboxGroupInput(inputId = "SelectItems",
label = "Which items would you like to select?",
choices = ItemList()),
radioButtons("RadioItems",
label = "Pick One",
choices = ItemList(),
selected = 1)
)
})
})
library(shiny)
shinyUI(fluidPage(
titlePanel("Create a checkboxGroupInput and a RadioButtons widget from a CSV"),
sidebarLayout(
sidebarPanel(fileInput(inputId = "CheckListFile", label = "Upload list of options")),
mainPanel(uiOutput("CustomCheckList")
)
)
))