结合 UI/UX 原则进行线框图设计
现在请为您的仪表板进行线框图设计,并应用一些相关原则。请注意,本练习不会渲染任何可视化。
设想您要为 Sally 创建一个仪表板。她的投资组合包含两只股票:Apple (AAPL) 和 Disney (DIS)。您会在她的仪表板中加入哪些内容?
可考虑的变量包括每只股票的每日开盘价与收盘价,分别用 open 和 close 表示,以及当日最高价与最低价,分别用 high 和 low 表示。另一个重要变量是当日成交量(即当日成交的股票数量),用 volume 表示。
本练习已为您引入 shinydashboard 和 shiny 库,并提供了一个空的 server() 函数。
本练习是课程的一部分
使用 shinydashboard 构建仪表板
交互式实操练习
通过完成这段示例代码来试试这个练习。
library(shinydashboard)
library(shiny)
header <- dashboardHeader(
title = "Portfolio dashboard for Sally",
titleWidth = 300
)
sidebar <- dashboardSidebar(
width = 300,
sidebarMenu(
id = "pages",
menuItem("Historical trends",
tabName = "historical"),
menuItem("Profits and Losses (PnLs)",
tabName = "profit",
icon = icon("money-bill-alt"),
# Truncate the number in the badge label to 2 decimal places
badgeLabel = "+2.324815454862%",
# Change the badge color to green
badgeColor = "red")
)
)
body <- dashboardBody(tabItems(
tabItem(tabName = "historical",
fluidRow(box(selectInput("stock", "Select stock symbol",
choices=c("AAPL", "DIS"))),
box("Stock name", width = 6)),
fluidRow(box("valueBox", "Open", width = 2),
box("valueBox", "High", width = 2),
box("valueBox", "Low", width = 2),
box("valueBox", "Close", width = 2),
box("valueBox", "Volume", width = 2)),
fluidRow(box("valueBox", "Open % change", width = 2, color = "red"),
box("valueBox", "High % change", width = 2),
box("valueBox", "Low % change", width = 2),
box("valueBox", "Close % change", width = 2),
box("valueBox", "Volume % change", width = 2))),
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)