1

I have uploaded a .csv file in Shiny App using fileInput(). I wish to read the column names and show them as options/choices in selectInput(). How do I do it?

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

Also can we use the variables in server part of code inside the ui part?

Raj
  • 21
  • 5

1 Answers1

1

It's not easy to answer without reprex. But here is my answer in theory.

add colnames() if you need column names.

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(''))
      )
}) 
phili_b
  • 885
  • 9
  • 27