Back to Skills

scaffold-shiny-app

pjt222
Updated 6 days ago
19 views
17
2
17
View on GitHub
Metadesigndata

About

This skill scaffolds new Shiny applications in R with three framework options: golem for production R packages, rhino for enterprise projects, or vanilla for quick prototypes. It handles project initialization and creates the first module, making it ideal for starting dashboards, data explorers, or production web apps. Use it when bootstrapping any interactive Shiny application to establish the proper structure from the beginning.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/scaffold-shiny-app

Copy and paste this command in Claude Code to install this skill

Documentation

架 Shiny 應

建新 Shiny 應含產備結構用 golem、rhino、或素架。

  • 始新互動 R 網應→用
  • 建儀板或資探原型→用
  • 設產 Shiny 應為 R 包(golem)→用
  • 啟企 Shiny 項(rhino)→用

  • :應名
  • :框選(golem、rhino、素)
  • :含模架(默:是)
  • :用 renv 管依(默:是)
  • :釋標(shinyapps.io、Posit Connect、Docker)

一:擇框

按項需選宜框:

結構
golem產應運為 R 包R 包含 DESCRIPTION、測、誌
rhino企應含 JS/CSS 建管box 模、Sass、JS 包、rhino::init()
速原型與學單 app.R 或 ui.R/server.R 對

得:明框決於項範與組需。

敗:未定→默 golem—予最多結構可後簡。素僅宜棄原型。

二:架項

Golem 路

golem::create_golem("myapp", package_name = "myapp")

建:

myapp/
├── DESCRIPTION
├── NAMESPACE
├── R/
│   ├── app_config.R
│   ├── app_server.R
│   ├── app_ui.R
│   └── run_app.R
├── dev/
├── inst/
├── man/
├── tests/
└── vignettes/

Rhino 路

rhino::init("myapp")

建:

myapp/
├── app/
│   ├── js/
│   ├── logic/
│   ├── static/
│   ├── styles/
│   ├── view/
│   └── main.R
├── tests/
├── app.R
├── dependencies.R
├── rhino.yml
└── renv.lock

素路

app.R

library(shiny)
library(bslib)

ui <- page_sidebar(
  title = "My App",
  sidebar = sidebar(
    sliderInput("n", "Sample size", 10, 1000, 100)
  ),
  card(
    card_header("Output"),
    plotOutput("plot")
  )
)

server <- function(input, output, session) {
  output$plot <- renderPlot({
    hist(rnorm(input$n), main = "Random Normal")
  })
}

shinyApp(ui, server)

得:項目建含諸架檔。

敗:golem→確 golem 包裝(install.packages("golem"))。rhino→自 GitHub 裝(remotes::install_github("Appsilon/rhino"))。素→確 shiny、bslib 裝。

三:配依

Golem/素

renv::init()

usethis::use_package("shiny")
usethis::use_package("bslib")
usethis::use_package("DT")
usethis::use_package("plotly")

renv::snapshot()

Rhino

依管於 dependencies.R

library(shiny)
library(bslib)
library(DT)

得:諸依錄於 DESCRIPTION(golem)或 dependencies.R(rhino)、renv 鎖。

敗:renv::init() 敗→查寫權。包裝敗→查 R 本相容。

四:建首模

Golem

golem::add_module(name = "dashboard", with_test = TRUE)

R/mod_dashboard.Rtests/testthat/test-mod_dashboard.R

Rhino

app/view/dashboard.R

box::use(
  shiny[moduleServer, NS, tagList, h3, plotOutput, renderPlot],
)

#' @export
ui <- function(id) {
  ns <- NS(id)
  tagList(
    h3("Dashboard"),
    plotOutput(ns("plot"))
  )
}

#' @export
server <- function(id) {
  moduleServer(id, function(input, output, session) {
    output$plot <- renderPlot({
      plot(1:10)
    })
  })
}

加模函至 R/mod_dashboard.R

dashboardUI <- function(id) {
  ns <- NS(id)
  tagList(
    h3("Dashboard"),
    plotOutput(ns("plot"))
  )
}

dashboardServer <- function(id) {
  moduleServer(id, function(input, output, session) {
    output$plot <- renderPlot({
      plot(1:10)
    })
  })
}

得:模檔建含 UI 與服函用正命空。

敗:確模 UI 函諸入/出 ID 用 NS(id)。無命空→ID 多用時撞。

五:行應

golem::run_dev()
shiny::runApp()
shiny::runApp("app.R")

得:應於瀏無誤啟。

敗:察 R 控制台誤訊。常題:缺包(裝之)、口已用(port = 3839)、UI/服碼語誤。

  • 應目結構合所擇框
  • shiny::runApp() 啟無誤
  • ≥ 1 模架含 UI 與服函
  • 依錄(DESCRIPTION 或 dependencies.R)
  • renv.lock 捕諸包本
  • 模用 NS(id) 命空隔

  • 產用素:素無測施、文、釋工。原型外用 golem 或 rhino
  • 模缺命空:模 UI 諸 inputIdoutputId 必裹 ns()。忘致默 ID 撞
  • golem 無 devtools 流:golem 應為 R 包。用 devtools::load_all()devtools::test()devtools::document(),非 source()
  • rhino 無 box:rhino 用 box 為模入。勿退 library()—用 box::use() 顯入

  • build-shiny-module
  • test-shiny-app
  • deploy-shiny-app
  • design-shiny-ui
  • create-r-package
  • manage-renv-dependencies

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan-ultra/skills/scaffold-shiny-app
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill