【问题标题】:I have uploaded a .csv file in Shiny.I want to read the column names and use them in selectInput as choices. How do I do it?我在 Shiny 中上传了一个 .csv 文件。我想读取列名并在 selectInput 中使用它们作为选择。我该怎么做?
【发布时间】:2020-04-07 19:49:12
【问题描述】:

我已经使用 fileInput() 在 Shiny App 中上传了一个 .csv 文件。 我希望阅读列名并将它们显示为 selectInput() 中的选项/选择。我该怎么做?

fileInput("file1", "Choose CSV File",
              multiple = FALSE,
              accept = c("text/csv",
                         "text/comma-separated-values,text/plain",
                         ".csv")),

我们也可以在ui部分中使用服务器部分代码中的变量吗?

【问题讨论】:

    标签: r shiny bootstrap-file-input


    【解决方案1】:

    没有reprex 就不容易回答。但这是我理论上的答案。

    如果您需要列名,请添加 colnames()

    ui.R

    uiOutput("myselectinputUI")
    

    server.R

    output$myselectinputUI <- renderUI({
        list_label_value <- input$file1
    
        # read my link with an other answer of mine below if you need many columns in the select input
    
        setNames(list_label_value$value,list_label_value$label)  
    
        selectizeInput(inputId="myselectinput",
                         label="Report Choice",
                         choices = list_label_value,
                         width = '500px',
                         selected = "1"
                         #  , options = list(render = I(''))
          )
    }) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-02
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 2019-12-27
      相关资源
      最近更新 更多