Home > Mobile >  Multiple fileInput in one line in shiny app
Multiple fileInput in one line in shiny app

Time:12-24

In my App I would like to have 3 fileInput object per row. How should I modify the code ? currently even if I define the column width It just put one fileInput in each row :

library(shiny)
library(shinythemes)
library(shinydashboard)

library(shinyWidgets)

ui <- fluidPage(
  theme = shinytheme("lumen"),
  shinyWidgets::useShinydashboard(),
  navbarPage("test theme",
             tabPanel("tab1",
                      mainPanel(width = 12,
                                fluidRow(
                                  box(width = 12, 
                                      title = "title", status = "primary", solidHeader = TRUE,
                                      numericInput("num","Number of file input",value = 2),
                                      column(width = 3,
                                      uiOutput("fIn"))
                                  )
                                )
                      )
             )
  )
)


server <- function(input, output, session) {
  output$fIn <- renderUI({
    ind = as.numeric(input$num)
    lapply(1:ind, function(k) {
      fileInput(paste0("fIn", k), paste('File:', k), accept=c("xlsx","text"))
      
    })
  })
}

shinyApp(ui, server)

CodePudding user response:

Instead of wrapping the uiOutput in column wrap each single fileInput in a column:

library(shinyWidgets)
library(shiny)
library(shinydashboard)

ui <- fluidPage(
  shinyWidgets::useShinydashboard(),
  navbarPage(
    "test theme",
    tabPanel(
      "tab1",
      mainPanel(
        width = 12,
        fluidRow(
          box(
            width = 12,
            title = "title", status = "primary", solidHeader = TRUE,
            numericInput("num", "Number of file input", value = 2),
            uiOutput("fIn")
          )
        )
      )
    )
  )
)


server <- function(input, output, session) {
  output$fIn <- renderUI({
    ind <- as.numeric(input$num)
    lapply(1:ind, function(k) {
      column(
        4,
        fileInput(paste0("fIn", k), paste("File:", k), accept = c("xlsx", "text"))
      )
    })
  })
}

shinyApp(ui, server)

enter image description here

  • Related