box()的Shinydashboard列布局

时间:2019-05-22 04:00:58

标签: r shinydashboard

我有一个看起来像这样的闪亮仪表板:

enter image description here

# Packages
library(shinydashboard)
library(tidyverse)
library(readxl)
library(scales)
theme_set(theme_light())


header <- dashboardHeader(
  title = "Test App",
  titleWidth = 215
)

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Test Tab", tabName = "test_tab",
             icon = icon("paper-plane"), startExpanded = TRUE)
  )
)


body <- dashboardBody(
  tabItems(
    tabItem(tabName = "test_tab",

            fluidRow(
              column(width = 4,
                     h2("Column X"),
                     valueBoxOutput("first_value", width = NULL),
                     box(flexdashboard::gaugeOutput("second_value", width = "90%", height = "100px"),
                         title = "Second Value", status = "primary", solidHeader = TRUE,
                         collapsible = FALSE, width = NULL
                     )
              ),
              column(width = 8,
                     h2("Column Y"),

                     box(
                       title = "#3", status = "primary", solidHeader = TRUE,
                       collapsible = FALSE, width = 4
                     ),
                     box(
                       title = "#4", status = "primary", solidHeader = TRUE,
                       collapsible = FALSE, width = 4
                     )
              )
            ),

            fluidRow(
              h2("Row A"),

              column(width = 12,

                     box(title = "Third Value", status = "primary", solidHeader = TRUE,
                         width = 2.4),

                     box("Fourth Value", status = "primary", solidHeader = TRUE,
                         width = 2.4),

                     box("Fifth Value", status = "primary", solidHeader = TRUE,
                         width = 2.4),


                     box("Sixth Value", status = "primary", solidHeader = TRUE,
                         width = 2.4),


                     box("Seventh Value", status = "primary", solidHeader = TRUE,
                         width = 2.4)
              )


            )

    )
  )
)


# Put them together into a dashboardPage
ui <- dashboardPage(skin = "blue", header = header,
                    sidebar = sidebar,
                    body = body)


server <- function(input, output) {

  output$first_value <- renderValueBox({

    valueBox(
      comma_format()(100000),
      subtitle = "First Value",
      icon = icon("list"), color = "purple"
    )
  })

  output$second_value = flexdashboard::renderGauge({
    flexdashboard::gauge(0.12 * 100,
                         symbol = '%',
                         min = 0, 
                         max = 100)
  })

}

shinyApp(ui, server)

我试图让RowA下面的box()以五列格式排列,如下所示:

Third Value | Fourth Value | Fifth Value | Sixth Value

我不确定在这里怎么做。我尝试将5个框放在fluidRow()内的column()内,该框应该可以工作,但不幸的是,这些框一直在水平显示...

反正有没有以列格式显示框?如果没有,您能否指导我使用其他类似于我的功能?

1 个答案:

答案 0 :(得分:0)

您已将这五个框的每个列宽指定为2.4(我猜是12/5)。

列宽应为整数。如果用2代替2.4,它将可以正常工作。

请注意,框5右侧将有一个空白列,与剩余的2(12-2 * 5)个位置相对应。

这基于引导程序列布局。有关更多信息,请参见this教程。