【问题标题】:create multiple shiny widgets with data from uploaded file使用上传文件中的数据创建多个闪亮的小部件
【发布时间】:2015-03-31 06:44:54
【问题描述】:

shiny 中,如何在renderUI 中使用tagList 来创建多个使用上传文件中的数据自定义的小部件?这个想法被引用了here,但是tagList似乎没有很好的文档。

我打算在这里回答我自己的问题。我做了一些研究,发现缺少此过程的一个简单示例,并希望贡献它以便其他人受益。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    在 server.R 中,使用 reactive() 语句定义一个对象来保存上传文件的内容。然后,在renderUI 语句中,将一个以逗号分隔的小部件定义列表包装在tagList 函数中。在每个小部件中,使用保存上传文件内容的对象作为小部件参数。下面的示例 hosted at shinyapps.ioavailable on github 使用基于上传文件定义的歌手 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)
        )
      })
    })
    

    ui.R

    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")
        )
      )
    ))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 2019-10-05
      • 2020-07-19
      相关资源
      最近更新 更多