shiny-bslib by posit-dev/skills
npx skills add https://github.com/posit-dev/skills --skill shiny-bslib利用 bslib 的 Bootstrap 5 组件和布局构建专业的 Shiny 仪表盘。本技能侧重于替代传统 Shiny 方法的现代化 UI/UX 模式。
单页仪表盘:
library(shiny)
library(bslib)
ui <- page_sidebar(
title = "My Dashboard",
theme = bs_theme(version = 5), # 默认为 "shiny" 预设
sidebar = sidebar(
selectInput("variable", "Variable", choices = names(mtcars))
),
layout_column_wrap(
width = 1/3,
fill = FALSE,
value_box(title = "Users", value = "1,234", theme = "primary"),
value_box(title = "Revenue", value = "$56K", theme = "success"),
value_box(title = "Growth", value = "+18%", theme = "info")
),
card(
full_screen = TRUE,
card_header("Plot"),
plotOutput("plot")
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
hist(mtcars[[input$variable]], main = input$variable)
})
}
shinyApp(ui, server)
多页仪表盘:
ui <- page_navbar(
title = "Analytics Platform",
theme = bs_theme(version = 5),
nav_panel("Overview", overview_ui),
nav_panel("Analysis", analysis_ui),
nav_panel("Reports", reports_ui)
)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
page_sidebar() -- 带侧边栏的单页仪表盘(最常见)page_navbar() -- 带顶部导航栏的多页应用page_fillable() -- 用于自定义排列的视口填充布局page_fluid() -- 用于长篇幅内容的滚动布局详见 page-layouts.md 获取详细指南。
layout_column_wrap() -- 自动换行的均匀网格(推荐用于大多数情况)layout_columns() -- 具有精确控制的 12 列 Bootstrap 网格详见 grid-layouts.md 获取详细指南。
仪表盘内容的主要容器。支持页眉、页脚、多个主体部分和全屏扩展。
详见 cards.md 获取详细指南。
显示关键指标和 KPI,支持可选图标、迷你图和内置主题。
详见 value-boxes.md 获取详细指南。
page_navbar() 用于多页应用navset_card_underline()、navset_tab()、navset_pill() 用于选项卡式内容详见 navigation.md 获取详细指南。
page_sidebar() 或 page_navbar(sidebar = ...)layout_sidebar()详见 sidebars.md 获取详细指南。
填充系统控制组件如何调整大小以填充可用空间。关键概念:可填充容器、填充项、填充载体。当容器定义了高度时,填充功能激活。
详见 filling.md 获取详细指南。
bs_theme() 配合 Bootswatch 主题实现快速样式设置bg、fg、primary 影响数百条 CSS 规则font_google() 用于排版input_dark_mode() + session$setCurrentTheme()详见 theming.md 获取详细指南。
推荐:bsicons 包(Bootstrap 图标,专为 bslib 设计):
bsicons::bs_icon("graph-up")
bsicons::bs_icon("people", size = "2em")
替代方案:fontawesome 包:
fontawesome::fa("envelope")
纯图标触发器的可访问性: 当图标用作工具提示、弹出框或类似交互元素的唯一触发器(没有伴随文本)时,必须对屏幕阅读器可访问。默认情况下,图标包将图标标记为装饰性(aria-hidden="true"),这会将其对辅助技术隐藏。
bsicons::bs_icon():提供 title -- 这会自动设置 a11y = "sem"
tooltip(
bs_icon("info-circle", title = "更多信息"),
"工具提示内容在此"
)
fontawesome::fa():设置 a11y = "sem" 并提供 title
tooltip(
fa("circle-info", a11y = "sem", title = "更多信息"),
"工具提示内容在此"
)
title 应描述触发器的目的(例如,“更多信息”、“设置”),而不是图标本身(例如,不是“信息圆圈图标”)。
input_switch() -- 切换开关(现代复选框替代品)input_dark_mode() -- 深色模式切换input_task_button() -- 用于长时间运行操作的按钮input_code_editor() -- 带语法高亮的代码编辑器input_submit_textarea() -- 带显式提交的文本区域详见 inputs.md 获取详细指南。
page_sidebar()(单页)或 page_navbar()(多页)bs_theme() 添加主题(考虑使用 Bootswatch 快速开始)fill = FALSE)layout_column_wrap() 或 layout_columns() 排列卡片full_screen = TRUEthematic::thematic_shiny() 用于绘图主题详见 migration.md 获取从传统模式到现代等效模式的完整映射。关键步骤:
fluidPage() 替换为 page_sidebar() 或 page_navbar()fluidRow()/column() 替换为 layout_columns()card(full_screen = TRUE) 中theme = bs_theme(version = 5)value_box() 组件tabsetPanel() 替换为 navset_card_underline()page_sidebar()、page_navbar()、page_fillable()、page_fluid())而非传统等效函数(fluidPage()、navbarPage())layout_column_wrap() 或 layout_columns() 进行网格布局,而不是 fluidRow()/column(),后者不支持填充布局card(full_screen = TRUE) 中 -- 全屏扩展是一项高价值功能layout_column_wrap() 容器上设置 fill = FALSE(它们不应拉伸以填充高度)theme = bs_theme(version = 5) 或预设主题thematic::thematic_shiny(),以便 base R 和 ggplot2 绘图与应用主题匹配layout_column_wrap() 中使用响应式宽度,如 width = "250px",以实现自动调整列宽accordion() 对侧边栏输入进行分组card() 容器。navset_card_*() 函数本身已经是卡片;nav_panel() 内容应直接放入其中,无需再包装在 card() 内layout_columns() 和 layout_column_wrap() 用于布局多个元素。单个子元素应直接传递给其容器函数。page_*() 函数。每个应用仅使用一个顶级页面函数。每周安装数
108
代码仓库
GitHub 星标数
207
首次出现
2026年2月20日
安全审计
安装于
opencode95
codex93
github-copilot91
gemini-cli90
cursor90
amp89
Build professional Shiny dashboards using bslib's Bootstrap 5 components and layouts. This skill focuses on modern UI/UX patterns that replace legacy Shiny approaches.
Single-page dashboard:
library(shiny)
library(bslib)
ui <- page_sidebar(
title = "My Dashboard",
theme = bs_theme(version = 5), # "shiny" preset by default
sidebar = sidebar(
selectInput("variable", "Variable", choices = names(mtcars))
),
layout_column_wrap(
width = 1/3,
fill = FALSE,
value_box(title = "Users", value = "1,234", theme = "primary"),
value_box(title = "Revenue", value = "$56K", theme = "success"),
value_box(title = "Growth", value = "+18%", theme = "info")
),
card(
full_screen = TRUE,
card_header("Plot"),
plotOutput("plot")
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
hist(mtcars[[input$variable]], main = input$variable)
})
}
shinyApp(ui, server)
Multi-page dashboard:
ui <- page_navbar(
title = "Analytics Platform",
theme = bs_theme(version = 5),
nav_panel("Overview", overview_ui),
nav_panel("Analysis", analysis_ui),
nav_panel("Reports", reports_ui)
)
page_sidebar() -- Single-page dashboard with sidebar (most common)page_navbar() -- Multi-page app with top navigation barpage_fillable() -- Viewport-filling layout for custom arrangementspage_fluid() -- Scrolling layout for long-form contentSee page-layouts.md for detailed guidance.
layout_column_wrap() -- Uniform grid with auto-wrapping (recommended for most cases)layout_columns() -- 12-column Bootstrap grid with precise controlSee grid-layouts.md for detailed guidance.
Primary container for dashboard content. Support headers, footers, multiple body sections, and full-screen expansion.
See cards.md for detailed guidance.
Display key metrics and KPIs with optional icons, sparklines, and built-in theming.
See value-boxes.md for detailed guidance.
page_navbar() for multi-page appsnavset_card_underline(), navset_tab(), navset_pill() for tabbed contentSee navigation.md for detailed guidance.
page_sidebar() or page_navbar(sidebar = ...)layout_sidebar() within cardsSee sidebars.md for detailed guidance.
The fill system controls how components resize to fill available space. Key concepts: fillable containers, fill items, fill carriers. Fill activates when containers have defined heights.
See filling.md for detailed guidance.
bs_theme() with Bootswatch themes for quick stylingbg, fg, primary affect hundreds of CSS rulesfont_google() for typographyinput_dark_mode() + session$setCurrentTheme()See theming.md for detailed guidance.
See accordions.md, tooltips-popovers.md, and toasts.md.
Recommended:bsicons package (Bootstrap Icons, designed for bslib):
bsicons::bs_icon("graph-up")
bsicons::bs_icon("people", size = "2em")
Browse icons: https://icons.getbootstrap.com/
Alternative:fontawesome package:
fontawesome::fa("envelope")
Accessibility for icon-only triggers: When an icon is used as the sole trigger for a tooltip, popover, or similar interactive element (no accompanying text), it must be accessible to screen readers. By default, icon packages mark icons as decorative (aria-hidden="true"), which hides them from assistive technology.
bsicons::bs_icon() : Provide title — this automatically sets a11y = "sem"
tooltip(
bs_icon("info-circle", title = "More information"),
"Tooltip content here"
)
fontawesome::fa() : Set a11y = "sem" and provide title
tooltip(
fa("circle-info", a11y = "sem", title = "More information"),
"Tooltip content here"
)
The title should describe the purpose of the trigger (e.g., "More information", "Settings"), not the icon itself (e.g., not "info circle icon").
input_switch() -- Toggle switch (modern checkbox alternative)input_dark_mode() -- Dark mode toggleinput_task_button() -- Button for long-running operationsinput_code_editor() -- Code editor with syntax highlightinginput_submit_textarea() -- Textarea with explicit submissionSee inputs.md for detailed guidance.
page_sidebar() (single-page) or page_navbar() (multi-page)bs_theme() (consider Bootswatch for quick start)fill = FALSE on container)layout_column_wrap() or layout_columns()full_screen = TRUE on all visualization cardsthematic::thematic_shiny() for plot themingSee migration.md for a complete mapping of legacy patterns to modern equivalents. Key steps:
fluidPage() with page_sidebar() or page_navbar()fluidRow()/column() with layout_columns()card(full_screen = TRUE)theme = bs_theme(version = 5)value_box() componentstabsetPanel() with page_sidebar(), page_navbar(), page_fillable(), page_fluid()) over legacy equivalents (fluidPage(), navbarPage())layout_column_wrap() or layout_columns() for grid layouts instead of fluidRow()/column(), which don't support filling layoutscard() containers. navset_card_*() functions are already cards; nav_panel() content goes directly inside them without wrapping in card()layout_columns() and layout_column_wrap() for laying out multiple elements. Single children should be passed directly to their container functions.page_*() functions. Only use one top-level page function per app.Weekly Installs
108
Repository
GitHub Stars
207
First Seen
Feb 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode95
codex93
github-copilot91
gemini-cli90
cursor90
amp89
ManimGL 最佳实践指南:场景、动画、3D 与交互式开发教程
863 周安装
navset_card_underline()card(full_screen = TRUE) when building dashboards -- full-screen expansion is a high-value featurefill = FALSE on layout_column_wrap() containers holding value boxes (they shouldn't stretch to fill height)theme = bs_theme(version = 5) or a preset themethematic::thematic_shiny() in the server so base R and ggplot2 plots match the app themewidth = "250px" in layout_column_wrap() for auto-adjusting columnsaccordion() when sidebars have many controls