สร้าง dashboard แรกของคุณ
ข้อมูลถูกเก็บไว้ในรูปแบบ data frame ชื่อ soccer โดยมีกราฟที่กำหนดไว้ล่วงหน้า 3 รายการ ได้แก่
goals_plot: จำนวนประตูที่แต่ละทีมทำได้yellow_plot,red_plot: จำนวนใบเหลือง/ใบแดงที่แต่ละทีมได้รับ
นอกจากนี้ยังมีฟังก์ชันช่วยเสริมที่กำหนดเอง ดังนี้
daytime_fn(): ดึงวันและเวลาของแต่ละแมตช์venue_fn(): ดึงสถานที่จัดการแข่งขันgrp_fn(): ดึงกลุ่มของการแข่งขันteam1_fn(),team2_fn(): ชื่อของทีมที่ 1 และทีมที่ 2score1_fn(),score2_fn(): จำนวนประตูที่ทีมที่ 1 และทีมที่ 2 ทำได้
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสร้างแดชบอร์ดด้วย shinydashboard
คำแนะนำการฝึกหัด
- เติมช่องว่างสำหรับ output ในแถวที่ 1 ถึง 3 ของแท็บ/หน้าแรก
- เติมช่องว่างสำหรับ output ของกราฟในหน้าที่ 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
___