시작하기무료로 시작하기

색상 설정

색상으로 구분하는 status 설정과는 별도로, valueBox()infoBox() 같은 객체에는 더 다양한 색상을 지정할 수 있어요.

Available colors

다음 연습에서는 shinydashboard의 본문에 서로 다른 색상을 지정해 보겠습니다. 이전 예제에서 본 것처럼, 이러한 객체는 server()에서 정의할 수도 있어요.

이 연습에서는 shinyshinydashboard 라이브러리가 이미 로드되어 있습니다. 또한 헤더와 사이드바는 각각 headersidebar로 저장되어 있고, server()는 빈 함수로 제공됩니다.

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

shinydashboard로 대시보드 만들기

강의 보기

실습형 인터랙티브 연습

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

library(shiny)
library(shinydashboard)

header <- dashboardHeader(
  title = "Portfolio dashboard for Sally",
  titleWidth = 300,
  dropdownMenu(type = "notifications",
       notificationItem("Sell alert", status = "danger"),
       notificationItem("Buy alert", status = "success"))
)

sidebar <- dashboardSidebar(
  width = 300,
  sidebarMenu(
    id = "pages",
    menuItem("Historical trends",
             tabName = "historical"),
    menuItem("Profits and Losses (PnLs)", 
             tabName = "profit", 
             icon = icon("money-bill-alt"),
             badgeLabel = "+2.3%", badgeColor = "green")
  )
)

body <- dashboardBody(tabItems(
  tabItem(tabName = "historical",
          fluidRow(box(selectInput("stock", "Select stock symbol", 
                                   choices=c("AAPL", "DIS"))),
                   box("Stock name", 
                       title="Stock name title", 
                       width = 6, 
                       status = "info", solidHeader = TRUE)),
          # Set the color of each infoBox to black
          fluidRow(infoBox("Open", "value", width = 2, color = ___), 
                   infoBox("High", "value", width = 2,___),
                   infoBox("Low", "value", width = 2, ___),
                   infoBox("Close", "value", width = 2, ___),
                   # Set the color of the last infoBox to navy and set its width to 4
                   infoBox("Volume", "value", ___)),
          fluidRow(valueBox("Open (%)", "0%", width = 2), 
                   valueBox("High (%)", "+1%", width = 2),
                   valueBox("Low (%)", "-4%", width = 2),
                   valueBox("Close (%)", "-2%", width = 2),
                   valueBox("Volume (%)", "+30%", width = 2)),
          fluidRow(box("Candlestick chart", width = 12, height = 350)),
          fluidRow(box("Volume chart", width = 12, height = 200))),
  tabItem(tabName = "profit",
          fluidRow(box("valueBox", "Account balance", width = 3),
                   box("valueBox",  "Value at Risk (Var)", width = 3),
                   box("valueBox", "Returns", width = 3),
                   box("valueBox", "Profit-to-loss ratio", width = 3)),
          fluidRow(box("PnL chart", width = 12, height = 400)))
)
)

ui <- dashboardPage(header, sidebar, body)
server <- function(input, output){}
shinyApp(ui, server)
코드 편집 및 실행