shiny-for-r
它能做什么
这项技能教智能体如何使用 R 语言的 Shiny 包构建交互式网页应用。它相当于一个索引,指向每项任务对应的专门指南,例如响应式编程或布局。
适用场景
- ✓当用户想构建或修复带有输入和输出的 Shiny for R 应用的时候。
- ✓当用户需要可复用的 Shiny 模块,或带卡片和主题的应用布局的时候。
- ✓当用户需要关于响应式值、异步任务或调试 Shiny 应用的帮助的时候。
技能链接
https://github.com/rstudio/shiny/blob/main/inst/skills/shiny-for-r/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我用 R 构建一个 Shiny 应用:用户选择地区后,图表会自动更新。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会阅读这个索引,打开与任务相符的一两份指南,并按照指南编写代码。没有对应指南的主题,则根据其对该包的一般了解来处理。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Shiny for R
A Shiny app has a ui object (or function), a server(input, output, session) function, and shinyApp(ui, server) to run them together. The
reactive graph is the engine: reading a reactive source (input$x, a
reactive(), a reactiveVal()) inside a reactive context registers a
dependency, so changing that source re-runs everything that read it — you
never call outputs or schedule updates yourself.
This skill is an index. Find your task below and read the linked reference file before writing code for that area. Read the one or two references your task actually touches, not all of them.
Not every corner of Shiny has a reference here — plain inputs
(selectInput(), actionButton(), ...), deployment, and app performance
tuning are not covered. For those, work from your own knowledge of the
package and its help pages.
Foundations
| Topic | Use when | Reference |
|---|---|---|
| Reactivity | A value should recompute or an output update as inputs change; choosing between reactive()/observe()/observeEvent(); req(), isolate(), bindEvent(), timers, polling |
references/reactivity.md |
| Modules | A reusable, repeatable UI+server component; avoiding input/output id collisions across copies | references/modules.md |
| Session lifecycle | Per-session cleanup (onSessionEnded()), flush hooks, unhandled errors, per-session vs app-level scope, session$userData |
references/session-lifecycle.md |
Async
| Topic | Use when | Reference |
|---|---|---|
| Async | Returning a promises::promise from a render/observer so R keeps serving other sessions during slow I/O |
references/async.md |
| Extended tasks | Running slow work in a background process while the session that started it stays fully interactive; task buttons | references/extended-tasks.md |
Dashboard building
| Topic | Use when | Reference |
|---|---|---|
| Dashboard design | Turning a dataset or brief into a polished analytical dashboard; information hierarchy, shared filters, responsive layout, empty states, final visual/functional pass | references/dashboard-design.md |
| Dashboard components | Composing bslib card(), value_box(), accordion(), tooltip()/popover() instead of hand-rolled div() markup |
references/dashboard-components.md |
| Layouts | Arranging a page with bslib page_sidebar(), layout_columns(), card() instead of nested fluidRow()/column() pyramids |
references/layouts.md |
Navigation & dynamic UI
| Topic | Use when | Reference |
|---|---|---|
| Navigation | Grouping switchable content into a real tab container/navbar instead of faking tabs with buttons plus conditionalPanel() |
references/navigation.md |
| Dynamic UI | UI that must change after render — update*Input(), conditionalPanel(), renderUI()/uiOutput(), or insertUI()/removeUI() |
references/dynamic-ui.md |
Outputs
| Topic | Use when | Reference |
|---|---|---|
| Plots | Pairing renderPlot()/plotOutput() for base/lattice/ggplot2 graphics; click/hover/brush interaction via nearPoints()/brushedPoints() |
references/plots.md |
| Tables | Choosing renderTable() (static), the deprecated renderDataTable(), or DT/reactable for sortable/searchable interactive tables |
references/tables.md |
| Files | fileInput() uploads and downloadHandler()/downloadButton() generated-file downloads |
references/files.md |
Feedback & state
| Topic | Use when | Reference |
|---|---|---|
| Feedback | Toasts/notifications, modal dialogs, progress bars, and input validation sent from the server, typically inside observeEvent() |
references/feedback.md |
| Bookmarking | Saving/restoring app state via a shareable URL instead of a hand-built query string or custom persistence layer | references/bookmarking.md |
Theming, assets & extending
| Topic | Use when | Reference |
|---|---|---|
| Theming & assets | Setting bslib::bs_theme() Sass variables, thematic for plot theming, brand.yml, or adding custom CSS/JS/image assets |
references/theming-assets.md |
| Custom components | Integrating a third-party JS widget or bespoke interaction when no built-in input/output covers it | references/custom-components.md |
Testing & observability
| Topic | Use when | Reference |
|---|---|---|
| Testing | Verifying server-side reactive logic with testServer() without starting a real Shiny process or browser |
references/testing.md |
| Debugging | Dropping into a |
常见问题
Shiny 应用如何更新输出?
响应式代码会在它所读取的输入变化时重新运行,因此无需手动更新输出。
什么是 Shiny 模块?
模块是可复用的界面和服务器代码,复制时不会产生 ID 冲突。
它涵盖部署吗?
不涵盖。这项技能说明,部署和应用性能调优不在范围之内。
详情
作者的原始描述
Building, styling, testing, debugging, or observing a Shiny for R app - library(shiny), shinyApp(), runApp(). Index skill: read this, then open the linked reference for the task. Covers reactivity (reactive/observe/req/isolate/bindEvent); modules; async promises and ExtendedTask; bslib layouts, navigation, cards, value boxes, and theming (incl. thematic and brand.yml); dynamic UI; plots with click/brush interaction; tables, file upload/download; notifications, modals, progress, validation; bookmarking; custom JS components; testServer testing; debugging; OpenTelemetry; and when to reach for DT
repo: rstudio/shiny
热度
- GitHub 星标
- 5.7k
- 排名
- #14753
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …