Search code examples
rshinyshinydashboardshiny-servershinyapps

How can I create x number of textInput which are arranged vertically?


I have a dataset called dat and I can find the number of columns present by x<-ncol(dat).

I want to create x number of textinputs which are shown vertically.

How can I do that?


Solution

  • Here's a simple example with lapply and iris dataset -

    library(shiny)
    
    dat <- iris
    x<-names(dat)
    
    ui <- fluidPage({
      uiOutput('textInput')
    })
    
    server <- function(input, output) {
      output$textInput <- renderUI({
        lapply(x, function(name) textInput(name, name))
      })
    }
    
    shinyApp(ui, server)
    

    enter image description here