最初のダッシュボードを作る
データは soccer というデータフレームに保存されています。あらかじめ3つのプロットが用意されています。
goals_plot: 各チームの得点数yellow_plot,red_plot: 各チームに出されたイエローカード/レッドカードの枚数
以下のカスタムヘルパー関数を使います。
daytime_fn(): 特定の試合の開催日と時刻を取得venue_fn(): 特定の試合の会場を取得grp_fn(): 対戦カードのグループを取得team1_fn(),team2_fn(): チーム1/チーム2の名称score1_fn(),score2_fn(): チーム1/チーム2の得点数
この演習はコースの一部です
shinydashboard で作るダッシュボード
演習の手順
- 最初のタブ/ページの1〜3行目にある出力の空欄を埋めてください。
- 2つ目のページにあるプロット出力("goals"、"yellow"、"red" と呼ばれる)についても空欄を埋めてください。
- UI と server を組み合わせて、shinydashboard を表示できるようにしてください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
body <- dashboardBody(tabItems(
tabItem(tabName = "matchtab",
fluidRow(selectInput("match", "Match number", choices = 1:nrow(soccer)),
infoBoxOutput("daytime"), infoBoxOutput("venue"), infoBoxOutput("grp")),
fluidRow(valueBoxOutput("team1", width = 3), valueBoxOutput("score1", width = 3),
valueBoxOutput("team2", width = 3), valueBoxOutput("score2", width = 3)),
fluidRow(plotOutput("histogram"))),
tabItem(tabName = "statstab",
tabBox(tabPanel("Goals", plotOutput("goals", height = "700px")),
tabPanel("Yellow cards", plotOutput("yellow", height = "700px")),
tabPanel("Red cards", plotOutput("red"))))
))
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
# Fill in outputs in first to third rows of the first page
output$daytime <- renderInfoBox(infoBox("Day and time",
daytime_fn(input$match),
icon = icon("calendar"),
color = "green"))
output$venue <- ___(infoBox("Venue",
venue_fn(input$match),
icon = icon("map"),
color = "green"))
output$___ <- ___(___("Group",
grp_fn(input$match),
color = "green"))
output$team1 <- ___(valueBox("Team 1", team1_fn(input$match), color = "blue"))
output$score1 <- ___(___("# of goals", score1_fn(input$match), color = "blue"))
output$___ <- ___(valueBox("Team 2", team2_fn(input$match), color = "red"))
___ <- ___(valueBox("# of goals", score2_fn(input$match), color = "red"))
output$histogram <- renderPlot(plot_histogram(input$match))
# Fill in outputs in the second page
output$goals <- ___(goals_plot)
output$___ <- ___(yellow_plot)
___ <- ___(red_plot)
}
# Put the UI and server together
___