시작하기무료로 시작하기

나만의 첫 대시보드 만들기

데이터는 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로 대시보드 만들기

강의 보기

연습 안내

  • 첫 번째 탭/페이지의 첫째 줄부터 셋째 줄까지 출력 요소의 빈칸을 채우세요.
  • 두 번째 페이지의 플롯 출력(이름은 "goals", "yellow", "red")의 빈칸을 채우세요.
  • UI와 서버를 함께 배치해 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
___
코드 편집 및 실행