状态、颜色与皮肤

使用 shinydashboard 构建仪表板

Png Kee Seng

Researcher

美化餐厅

  • 自定义仪表板就像美化餐厅
  • 常说"先用眼睛吃"
  • 更美观的仪表板带来更好体验
  • 先从更改部分元素的颜色入手

美化的餐厅与赏心悦目的食物。

1 图片来源:Freepik
使用 shinydashboard 构建仪表板

shinydashboard 的状态

  • 部分 shinydashboard 对象有 status 属性
  • 通过 status 参数设置状态
    <object>(status = <status>, ...)
    

shinydashboard 中的状态

使用 shinydashboard 构建仪表板

notificationItem 的状态

  • 在页眉中添加两个通知项
    • 将买入警报设为 success
    • 将卖出警报设为 danger
  • notificationItem() 的默认状态为 "success"

notificationItem 的 success 与 danger 状态。

header <- dashboardHeader(
  ...
  dropdownMenu(type = "notifications",

notificationItem("Sell alert",
status = "danger"
),
notificationItem("Buy alert",
status = "success"
)
)) ...
使用 shinydashboard 构建仪表板

盒子的状态

  • 不设置 status 时,盒子无颜色
  • status 设为 "info"
  • 设置标题
  • 设为 solidHeader = TRUE
...
body <- dashboardBody(...,
        box("Stock name",

title="Stock name title",
width = 6,
status = "info",
solidHeader = TRUE)),
...

info 状态的盒子。

带标题的 info 状态盒子。

info 状态、标题与实心填充的盒子。

使用 shinydashboard 构建仪表板

为 shinydashboard 添加颜色

  • 在部分 shinydashboard 对象中可设置 color
  • 假设 close 价较昨日下跌 2%
    • 渲染红色的 valueBox() 以提醒 Sally

我们可以为 valueBox() 着色。

...
body <- dashboardBody(...,

valueBox("Close (%)", "-2%", width = 2,
color = "red"
),
...) ...
使用 shinydashboard 构建仪表板

更多颜色

  • shinydashboard 可用颜色:

shinydashboard 中可用的颜色。

  • 使用 ?validStatuses?validColors 查看可用状态与颜色
使用 shinydashboard 构建仪表板

shinydashboard 的皮肤

  • shinydashboard 内置多种皮肤
  • dashboardPage()skin 参数中设置
dashboardPage(skin = <color>)

可选颜色

  • "blue"(默认)
  • "black"
  • "purple"
  • "green"
  • "red"
  • "yellow"
使用 shinydashboard 构建仪表板

尝试不同皮肤

  • 将颜色设为 purple 试试
  • 改为 black 比较差异
ui <- dashboardPage(skin = "purple",
                    header, sidebar, body)
ui <- dashboardPage(skin = "black",
                    header, sidebar, body)

紫色皮肤。

黑色皮肤

使用 shinydashboard 构建仪表板

Vamos praticar!

使用 shinydashboard 构建仪表板

Preparing Video For Download...