開始使用免費開始

主體(body),並完成 UI

你已經設定好標頭(header)與側邊欄(sidebar)。現在,來設定主體(body)。

這是線框規劃流程中很關鍵的一步,因為它能幫你決定要把各種輸出與輸入放在儀表板主體中的哪個位置。

在這個練習中,你會把多個輸出與輸入放進儀表板。完成之後,你將取得使用者介面的三個組件,並在 dashboardPage() 中組合起來。

<說明:由於包含一些隱藏函式,這個儀表板無法在本機重現。>

本練習屬於課程

使用 shinydashboard 建立儀表板

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

header <- dashboardHeader(title = "Soccer tournament")

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Matches", tabName = "matchtab", icon = icon("futbol")), 
    menuItem("General statistics", tabName = "statstab", icon = icon("chart-line")) 
  )
)

body <- dashboardBody(tabItems(
  tabItem(tabName = "matchtab", 
  fluidRow(selectInput("match", "Match number", choices = 1:nrow(soccer))) 
         ),
  # See that the second tab should contain three sub-tabs
  ___(tabName = ___, 
          ___(tabPanel("Goals"), 
                 ___("Yellow cards"),
                 ___(___))
         )
))
編輯並執行程式碼