开始使用免费开始使用

线框图(Wireframing)

让我们回到之前的示例:一个用于展示足球锦标赛分析结果的仪表板。在前面的练习中,您已经设置好了页眉和侧边栏。

具体来说,侧边栏中的按钮由 menuItem() 定义,并包含在 sidebarMenu() 中。您可能已经注意到,这些按钮目前还没有任何作用。接下来,您将把这些侧边栏按钮链接到 UI 主体中的不同页面。这仍然属于线框图阶段,您还在决定各个对象的摆放位置。主体中的每个页面由 tabItem() 定义,并且必须包含在 tabItems 中。

shinyshinydashboard 包已经为您加载。同时,仪表板的页眉已存为 header

本练习是课程的一部分

使用 shinydashboard 构建仪表板

查看课程

交互式实操练习

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

library(shiny)
library(shinydashboard)

header <- dashboardHeader(
  title = "Analysis results for global soccer tournament",
  titleWidth = 400,
  dropdownMenu(type = "messages",
               messageItem("Colleage", "Hello world!")),
  dropdownMenu(type = "notifications",
               notificationItem("Have you rested today?"),
               taskItem("Dashboard completion", value = 20)))

sidebar <- dashboardSidebar(
  sidebarMenu(
    width = 400,
    id = "pages",
    menuItem("Match details", tabName = "matches", icon = icon("futbol"),
             badgeLabel = "New content!", badgeColor = "green"),
    menuItem("Overall results", tabName = "overall", 
             menuSubItem("Charts", tabName = "charts"),
             menuSubItem("Data table", tabName = "datatable", icon=icon("file-excel"))),
    menuItem("A slider",  sliderInput("slider", "Number of goals", min=0, max=10, value = 2))
  )
)

body <- dashboardBody(
  # Link "matches" to an empty page in the body
  ___(
    ___(___, "Match information goes here")
  )
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output){}
shinyApp(ui, server)
编辑并运行代码