返回技能列表

scaffold-shiny-app

pjt222
更新于 2 days ago
4 次查看
17
2
17
在 GitHub 上查看
设计design

关于

This skill scaffolds new Shiny applications in R with three framework options: golem for production packages, rhino for enterprise applications, or vanilla for quick prototypes. It handles framework selection, project initialization, and can generate a first module. Use it when starting interactive R web apps, dashboard prototypes, or production-ready Shiny applications.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/scaffold-shiny-app

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Scaffold Shiny App

Create new Shiny w/ prod-ready structure → golem|rhino|vanilla.

Use When

  • New interactive R web app
  • Dashboard|data explorer proto
  • Prod Shiny as R pkg (golem)
  • Enterprise Shiny (rhino)

In

  • Required: App name
  • Required: Framework (golem|rhino|vanilla)
  • Optional: Module scaffold (default yes)
  • Optional: renv (default yes)
  • Optional: Deploy target (shinyapps.io|Posit Connect|Docker)

Do

Step 1: Choose Framework

FrameworkBest ForStructure
golemProduction apps shipped as R packagesR package with DESCRIPTION, tests, vignettes
rhinoEnterprise apps with JS/CSS build pipelinebox modules, Sass, JS bundling, rhino::init()
vanillaQuick prototypes and learningSingle app.R or ui.R/server.R pair

→ Clear decision by scope + team needs.

If err: unsure → default golem (most structure, can simplify). Vanilla only for throwaway protos.

Step 2: Scaffold

Golem

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

Creates:

myapp/
├── DESCRIPTION
├── NAMESPACE
├── R/
│   ├── app_config.R
│   ├── app_server.R
│   ├── app_ui.R
│   └── run_app.R
├── dev/
│   ├── 01_start.R
│   ├── 02_dev.R
│   ├── 03_deploy.R
│   └── run_dev.R
├── inst/
│   ├── app/www/
│   └── golem-config.yml
├── man/
├── tests/
│   ├── testthat.R
│   └── testthat/
└── vignettes/

Rhino

rhino::init("myapp")

Creates:

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

Vanilla

Create 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)

→ Project dir created w/ all scaffold files.

If err: golem → install.packages("golem"). Rhino → remotes::install_github("Appsilon/rhino"). Vanilla → ensure shiny+bslib installed.

Step 3: Configure Deps

Golem/Vanilla

# Initialize renv
renv::init()

# Add core dependencies
usethis::use_package("shiny")
usethis::use_package("bslib")
usethis::use_package("DT")         # if using data tables
usethis::use_package("plotly")     # if using interactive plots

# Snapshot
renv::snapshot()

Rhino

Deps managed in dependencies.R:

# dependencies.R
library(shiny)
library(bslib)
library(DT)

→ All deps recorded in DESCRIPTION (golem) | dependencies.R (rhino) + renv-locked.

If err: renv::init() fails → check write perms. Pkg install fails → check R ver compat.

Step 4: First Module

Golem

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

Creates R/mod_dashboard.R + tests/testthat/test-mod_dashboard.R.

Rhino

Create 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)
    })
  })
}

Vanilla

Add to 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)
    })
  })
}

→ Module file w/ UI+server using proper namespacing.

If err: ensure NS(id) for all input/output IDs in UI fn. Without → IDs collide on multi-use.

Step 5: Run

# Golem
golem::run_dev()

# Rhino
shiny::runApp()

# Vanilla
shiny::runApp("app.R")

→ App launches in browser w/o errs.

If err: check R console. Common: missing pkgs (install), port in use (port = 3839), syntax errs in UI/server.

Check

  • App dir has correct structure for framework
  • shiny::runApp() launches w/o errs
  • ≥1 module w/ UI+server
  • Deps recorded (DESCRIPTION|dependencies.R)
  • renv.lock captures vers
  • Module uses NS(id) for namespace isolation

Traps

  • Vanilla for prod: Lacks tests, docs, deploy tooling. Use golem|rhino beyond protos.
  • Missing namespace in modules: Every inputId+outputId must wrap ns(). Forget → silent ID collisions.
  • golem w/o devtools: golem apps are R pkgs. Use devtools::load_all(), test(), document() — not source().
  • rhino w/o box: rhino uses box for imports. Don't fall back to library() — use box::use().

  • build-shiny-module — reusable modules w/ namespace isolation
  • test-shiny-app — shinytest2 + testServer() tests
  • deploy-shiny-app — deploy to shinyapps.io, Posit Connect, Docker
  • design-shiny-ui — bslib theming + responsive
  • create-r-package — R pkg scaffold (golem apps are R pkgs)
  • manage-renv-dependencies — detailed renv mgmt

GitHub 仓库

pjt222/agent-almanac
路径: i18n/caveman-ultra/skills/scaffold-shiny-app
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

executing-plans

设计

该Skill用于当开发者提供完整实施计划时,以受控批次方式执行代码实现。它会先审阅计划并提出疑问,然后分批次执行任务(默认每批3个任务),并在批次间暂停等待审查。关键特性包括分批次执行、内置检查点和架构师审查机制,确保复杂系统实现的可控性。

查看技能

requesting-code-review

设计

该Skill可在完成任务、实现主要功能或合并代码前自动调度代码审查子代理,确保实现符合需求和计划。它支持通过指定git SHA范围进行精准的代码变更审查,帮助开发者在关键节点及时发现潜在问题。核心原则是"早审查、勤审查",适用于开发流程的各个关键阶段。

查看技能

connect-mcp-server

设计

这个Skill指导开发者如何将MCP服务器连接到Claude Code,支持HTTP、stdio和SSE三种传输协议。它涵盖了从安装配置到认证安全的完整流程,适用于集成GitHub、Notion、数据库等外部服务。当开发者需要添加集成、配置外部工具或提及MCP相关功能时,这个Skill能提供实用的操作指南。

查看技能

web-cli-teleport

设计

该Skill帮助开发者根据任务特性选择Claude Code的Web或CLI界面,并指导如何在两种环境间无缝迁移会话。它能分析任务复杂度、迭代需求等要素,推荐最优工作界面和工作流。关键特性包括会话状态管理、环境切换指导和上下文优化建议。

查看技能