Shiny 中的对象分配

objects allocation in Shiny

我正在尝试制作一种包含 3 个主题的仪表板。因此,我制作了 3 个框,但我想要实现的是主页中的 3 个框,它们将覆盖页面的整个宽度,但它们非常窄。 根据我的理解,整个页面的宽度是 12 个单位,所以我做了这样的代码:

library(shiny)
library(shinydashboard)

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Dashboard", tabName = "main", icon = icon("dashboard")),
    menuItem("Widgets", icon = icon("th"), tabName = "widgets")
  )
)

body <- dashboardBody(
  tabItems(
    tabItem(tabName = "main",
            tags$head(
              tags$style(HTML("
                              h2,h4{
                              text-align: center;
                              }
                              "
              ))
              ),
            h2("Title"),
            h4("Dashboard"),
            fluidRow(
              column(4,
                     box(title="Advance Analysis Tools", hr(),
                         tags$ul( tags$li("Object"), tags$li("Object"), tags$li("Object"), tags$li("Object") ))),
              column(4,
                     box(title="Quality",hr(),
                         tags$ul( tags$li("Object"),tags$li("Object")) )),
              column(4,
                     box(title="Operation",hr(),
                         tags$ul( tags$li("Object"),tags$li("Object"),tags$li("Object"),tags$li("Object"), tags$li("Object"), tags$li("Object") )))
            )
              )

              )
            )

ui <- dashboardPage(
  dashboardHeader(title = "Dashboard"),
  sidebar,
  body
)

server <- function(input, output) {

}

shinyApp(ui, server)

但是3个盒子没有正确铺开。

请指教。

提前致谢,

迈克尔

box() 函数也有一个宽度参数,就像您在 column() 函数中使用的一样。 您可能已经知道 12 是该参数的最大值。 请注意,框的宽度与列宽有关。宽度参数为 4 的列包括宽度参数为 12 的框会导致列完全被框填充且宽度为 4。

所以你可以使用类似的东西。

 column(4, 
   box(title="Operation",hr(), width = 12, ...

如果你想去掉中间的空格,请使用 sthg,例如: offset = 0, style='padding:0px;' 看这里: