始める無料で始める

ワイヤーフレームの作成

前章で扱った、サッカー大会の分析結果用ダッシュボードの例に戻りましょう。これまでの演習で、すでにヘッダーとサイドバーは設定済みです。

特に、サイドバーのボタンは 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)
コードを編集して実行