我已经在Shiny中上传了一个.csv文件。我想读取列名,并在selectInput中使用它们作为选择。我该怎么办?

问题描述 投票:1回答:1

我已使用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个回答
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(''))
      )
}) 
© www.soinside.com 2019 - 2024. All rights reserved.