시작하기무료로 시작하기

상태(status)와 UI 완성하기

좋은 UI의 원칙 중 하나는 색상을 직관적으로 사용하는 것입니다. 다행히 shinydashboard에서는 일부 요소에 상태(status)를 설정할 수 있어요. box(), notificationItem(), dropdownMenu() 같은 적절한 요소에 status 인수를 추가해 설정합니다. 다만, 뒤의 두 함수는 이 강의에서 다루지 않습니다.

status = "success"는 녹색, status = "danger"는 빨간색, status = "warning"는 주황색으로 표시됩니다.

이 연습은 강의의 일부입니다

shinydashboard로 대시보드 만들기

강의 보기

연습 안내

  • 세 번째 행의 첫 번째 박스 상태를 "success"로 바꾸세요.
  • 두 번째 행의 ValueBox() 값이 지정된 28~33번째 줄을 참고하여, 세 번째 행의 박스에도 동일하게 적용하세요.
  • 이전 단계에서 "line"이라고 이름 붙인 plotly 객체의 출력을 정의하세요.
  • 방금 정의한 uiserver를 사용해 shinydashboard를 렌더링하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

header <- dashboardHeader(title = "Portfolio information")
sidebar <- dashboardSidebar(disable = TRUE)

body <- dashboardBody(
          fluidRow(box(selectInput("stock", "Stock name", choices = c("AAPL", "DIS")))),
          fluidRow(valueBoxOutput("name", width = 2), 
                   valueBoxOutput("open", width = 2), 
                   valueBoxOutput("close", width = 2), 
                   valueBoxOutput("high", width = 2), 
                   valueBoxOutput("low", width = 2), 
                   valueBoxOutput("vol", width = 2)),
          # Change status to "success"
          fluidRow(box("This stock is in your portfolio", width = 2, status = "danger"), 
                   valueBoxOutput("open_pct", width = 2), 
                   valueBoxOutput("close_pct", width = 2), 
                   valueBoxOutput("high_pct", width = 2), 
                   valueBoxOutput("low_pct", width = 2), 
                   valueBoxOutput("vol_pct", width = 2)),
          fluidRow(box(plotlyOutput("line")), 
                   box(radioButtons("feature", "Features", 
                       choiceNames = c("Open", "Close", "High", "Low", "Volume"),
                       choiceValues = c("open", "close", "high", "low", "volume")) ) )
          )

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output) {
  output$name <- renderValueBox(valueBox("Stock name", get_name(input$stock), color = "black"))
  output$open <- renderValueBox(valueBox("Open price", most_recent(input$stock, "open"), color = "black"))
  output$close <- renderValueBox(valueBox("Close price", most_recent(input$stock, "close"), color = "black"))
  output$high <- renderValueBox(valueBox("High", most_recent(input$stock, "high"), color = "black"))
  output$low <- renderValueBox(valueBox("Low", most_recent(input$stock, "low"), color = "black"))
  output$vol <- renderValueBox(valueBox("Volume", most_recent(input$stock, "volume"), color = "black"))
  # Specify the values for ValueBoxes in the third row
  output$open_pct <- ___(valueBox("Change", paste0(most_recent_pct(input$stock, "open"),"%"), color = box_color(most_recent_pct(input$stock, "open"))))
  ___ <- ___(___("Change", paste0(most_recent_pct(input$stock, "close"),"%"), color = box_color(most_recent_pct(input$stock, "close"))))
  ___ <- ___(___("Change", paste0(most_recent_pct(input$stock, "high"),"%"), color = box_color(most_recent_pct(input$stock, "high"))))
  ___ <- ___(___("Change", paste0(most_recent_pct(input$stock, ___),"%"), color = box_color(most_recent_pct(input$stock, ___))))
  ___ <- ___(___("Change", paste0(most_recent_pct(___, ___),"%"), color = box_color(most_recent_pct(___, ___))))
  # Plotly object in the fourth row
  ___ <- ___(plot_line(input$stock, input$feature))
}

# Render the dashboard using shinyApp()
___
코드 편집 및 실행