开始使用免费开始使用

设置状态

视频中强调的良好 UI/UX 做法之一是有效使用颜色。正如您所见,通过设置相应的参数,可以为 box()notificationItem() 添加按颜色区分的状态。

Available statuses

这样,您就能利用这些预设颜色,帮助用户无需细看也能快速判断消息的性质。

接下来,您将在 shinydashboard 中尝试不同的状态。

本练习中,shinyshinydashboard 库已为您加载。另有 header 和 sidebar 已分别存为 sidebar,且 server() 是一个空函数。

本练习是课程的一部分

使用 shinydashboard 构建仪表板

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

library(shiny)
library(shinydashboard)

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")
  )
)

header <- dashboardHeader(
  title = "Portfolio dashboard for Sally",
  titleWidth = 300,
  dropdownMenu(type = "notifications",
               # Change status of "Sell alert" from "warning" to "danger"
               notificationItem("Sell alert", status = "warning"),
               # Set status of "Buy alert" to "success".
               notificationItem("Buy alert", ___))
)

body <- dashboardBody()

ui <- dashboardPage(header, sidebar, body)
server <- function(input, output){}
shinyApp(ui, server)
编辑并运行代码