输入数量为n的闪亮仪表板框中的自动换行符

时间:2019-11-14 14:21:22

标签: r shiny rstudio shinydashboard box

考虑以下应用:

library(shiny)
library(shinydashboard)
library(tidyverse)

ui <-  dashboardPage(
        dashboardHeader(),
        dashboardSidebar(),
        dashboardBody(
           fluidRow(box(numericInput("number", "Number of inputs", 10, 1, 50))),
           fluidRow(box(width = 12, uiOutput("SELECTS")))    
))

server <- function(input, output) {

    output$SELECTS <-  renderUI({
       sel_list <- map(seq(input$number), ~ {
            selectInput(paste0("select_", .x), label = .x, choices = seq(.x))
        })   
    })
}

shinyApp(ui = ui, server = server)

enter image description here

我想插入一个自动换行符,以将selectInputs安排在例如两四列。 对于10个这样的输入,可以采用非常硬编码的方式进行:

server <- function(input, output) {

output$SELECTS <-  renderUI({
   sel_list <- map(seq(input$number), ~ {
        selectInput(paste0("select_",.x), label = .x, choices = seq(.x))
    })

   fluidRow(column(width = 6, sel_list[1:5]), 
            column(width = 6, sel_list[6:10]))
})
}

enter image description here

但是必须有一种更优雅的方法来自动将输入数量分为一,二,三或四列。

0 个答案:

没有答案