การตั้งค่า status
หนึ่งในแนวทาง UI/UX ที่ดี ซึ่งได้กล่าวถึงในวิดีโอ คือการใช้สีอย่างมีประสิทธิภาพ อย่างที่เห็นไปแล้ว สามารถเพิ่ม status ที่มีรหัสสีให้กับ box() และ notificationItem() ได้ด้วยการกำหนดอาร์กิวเมนต์ที่เหมาะสม

วิธีนี้ช่วยให้ผู้ใช้เข้าใจลักษณะของข้อความได้อย่างรวดเร็ว โดยไม่ต้องอ่านรายละเอียดทั้งหมด
ในส่วนต่อไปนี้ ลองใช้ status ต่างๆ ใน shinydashboard กัน
ในแบบฝึกหัดนี้ ได้โหลดไลบรารี shiny และ shinydashboard ไว้ให้แล้ว นอกจากนี้ 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)