Search code examples
rshinyflowlayout

How to make dynamically generated shiny UI elements 'flow'


I am trying to dynamically generate shinyn UI elements placed horizontally one after another (left to right). The flowlayout seems perfect for it, however when the elements are dynamically generated using lapply it is being treated as a single element, and get placed vertically one below another.

Example code below

if (interactive()) {

  ui <- flowLayout(
    lapply(1:4,function(i){
      selectInput(paste0("input_1",i),"input", choices=1:5)
    })
  )
  shinyApp(ui, server = function(input, output) { })
}

However when not generated dynamically they are placed horizontally(left to right) one after an other, which is what I am looking for. Any pointers as to how this can be fixed?

EDIT: I found this nice response to a similar problem here, but Im wondering if a non 'eval-parse' solution possible


Solution

  • library(shiny)
    
    ui <- fluidPage(
      do.call(flowLayout,
              lapply(1:4, function(i){
                selectInput(paste0("input_1",i), "input", choices=1:5)
              })
      )
    )
    
    shinyApp(ui, server = function(input, output) { })