技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
scaffold-shiny-app【数据与研究】Scaffold a new Shiny application using golem (production R package), rhino (enterprise), or vanilla (quick prototype) structure. Covers framework selection, project initialization, and first module creation. Use when starting a new interactive web application in R, creating a dashboard or data explorer prototype, setting up a production Shiny app as …
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Make new Shiny app with prod-ready structure. Use golem, rhino, or vanilla scaffolding.
Judge project needs to pick framework.
| Framework | Best For | Structure |
|---|---|---|
| golem | Production apps shipped as R packages | R package with DESCRIPTION, tests, vignettes |
| rhino | Enterprise apps with JS/CSS build pipeline | box modules, Sass, JS bundling, rhino::init() |
| vanilla | Quick prototypes and learning | Single app.R or ui.R/server.R pair |
Got: Clear framework decision based on scope, team needs.
If fail: Unsure? Default to golem — most structure, can simplify later. Vanilla only for throwaway prototypes.
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::init("myapp")
Creates.
myapp/
├── app/
│ ├── js/
│ ├── logic/
│ ├── static/
│ ├── styles/
│ ├── view/
│ └── main.R
├── tests/
│ ├── cypress/
│ └── testthat/
├── .github/
├── app.R
├── dependencies.R
├── rhino.yml
└── renv.lock
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)
Got: Project dir made with all scaffolding files.
If fail: Golem? Ensure golem package installed: install.packages("golem"). Rhino? Install from GitHub: remotes::install_github("Appsilon/rhino"). Vanilla? Ensure shiny + bslib installed.
# 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()
Deps managed in dependencies.R.
# dependencies.R
library(shiny)
library(bslib)
library(DT)
Got: All deps recorded in DESCRIPTION (golem) or dependencies.R (rhino), locked with renv.
If fail: renv::init() fails? Check write perms. Packages fail to install? Check R version compat.
golem::add_module(name = "dashboard", with_test = TRUE)
Creates R/mod_dashboard.R and tests/testthat/test-mod_dashboard.R.
Make 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)
})
})
}
Add module functions to separate file 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)
})
})
}
Got: Module file made with UI + server functions using proper namespacing.
If fail: Ensure module uses NS(id) for all input/output IDs in UI function. Without namespacing, IDs collide when module used multiple times.
# Golem
golem::run_dev()
# Rhino
shiny::runApp()
# Vanilla
shiny::runApp("app.R")
Got: App launches in browser without errors.
If fail: Check R console for error msgs. Common: missing packages (install), port in use (specify different port port = 3839), syntax errors in UI/server.
shiny::runApp() launches without errorsNS(id) for proper namespace isolationinputId and outputId in module UI must be wrapped with ns(). Forget = silent ID collisions.devtools::load_all(), devtools::test(), devtools::document() — not source().library() calls — use box::use() for explicit imports.build-shiny-module — make reusable Shiny modules with proper namespace isolationtest-shiny-app — set up shinytest2 and testServer() testsdeploy-shiny-app — deploy to shinyapps.io, Posit Connect, Dockerdesign-shiny-ui — bslib theming + responsive layout designcreate-r-package — R package scaffolding (golem apps are R packages)manage-renv-dependencies — detailed renv dep management