开始使用免费开始使用

用 box 进行线框图设计

使用 fluidRow() 可以定义新的一行。

此外,可以在 body 中添加 box() 来组织内容。可以添加多个 box(),每个的默认宽度为 6,并可通过 width 参数进行调整。由于一行的最大宽度为 12,因此一行中默认最多只能放置两个 box()。您也可以设置 height,从而添加不同尺寸的 box。

在这里,这些 box() 有两个主要用途。第一,用于组织您的 shinydashboard 的各个元素;第二,用于进行线框图设计,便于在添加具体内容前先规划各对象的摆放位置。

本练习中,您将使用空的 box 进行线框图设计。

shinyshinydashboard 包已加载。仪表板的 header 和 sidebar 分别存为 headersidebar

本练习是课程的一部分

使用 shinydashboard 构建仪表板

查看课程

练习说明

  • 在第一行中,添加三个 box(),宽度分别为 2、2 和 8。
  • 在第二行中,添加一个占满整行且高度为 200 的 box()
  • 在第三行中,添加两个等宽的空 box,并分别标注为 "A slider goes here" 和 "Some info boxes go here"。

交互式实操练习

通过完成这段示例代码来试试这个练习。

body <- dashboardBody(
  # Add three boxes with widths 2, 2 and 8
  fluidRow(box("Some buttons go here", ___, height = 100), 
           ___("Checkboxes go here", ___, height = 50),
           ___("A chart goes here", ___, height = 150)),
  # Add one box that fills the entire row and has height 200
  fluidRow(___("Data table goes here"), ___, ___),
  # Add a third row containing two boxes with equal widths
  fluidRow(___)
)

ui <- dashboardPage(header, sidebar, body)
server <- function(input, output){}
shinyApp(ui, server)
编辑并运行代码