返回技能列表

deploy-shiny-app

pjt222
更新于 Yesterday
6 次查看
17
2
17
在 GitHub 上查看
aiautomation

关于

This skill deploys Shiny applications to shinyapps.io, Posit Connect, or Docker containers. It handles configuration, manifest generation, Dockerfile creation, and deployment verification. Use it to publish apps for users, move from local development to hosted environments, or containerize apps for deployment pipelines.

快速安装

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/deploy-shiny-app

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

技能文档

Deploy Shiny App

Shiny app → shinyapps.io / Posit Connect / Docker.

Use When

  • Publish Shiny → users
  • Local → hosted env
  • Containerize → K8s/Docker
  • Auto deploy pipelines

In

  • Required: App path
  • Required: Target (shinyapps.io / Posit Connect / Docker)
  • Optional: Account + token
  • Optional: Instance size
  • Optional: Custom domain/URL

Do

Step 1: Prep app

Self-contained + deployable:

# Check for missing dependencies
rsconnect::appDependencies("path/to/app")

# For golem apps, ensure DESCRIPTION lists all Imports
devtools::check()

# Verify the app runs cleanly
shiny::runApp("path/to/app")

Files:

  • app.R (or ui.R + server.R)
  • renv.lock (recommend reproducible)
  • .Rprofile does NOT call mcptools::mcp_session() in prod

→ App runs locally clean + all deps captured.

If err: appDependencies() missing pkgs → install + update renv.lock. Sys libs (gdal, curl) → note for Docker path.

Step 2a: shinyapps.io

# One-time account setup
rsconnect::setAccountInfo(
  name = "your-account",
  token = Sys.getenv("SHINYAPPS_TOKEN"),
  secret = Sys.getenv("SHINYAPPS_SECRET")
)

# Deploy
rsconnect::deployApp(
  appDir = "path/to/app",
  appName = "my-app",
  appTitle = "My Application",
  account = "your-account",
  forceUpdate = TRUE
)

Creds → .Renviron (never code):

# .Renviron
SHINYAPPS_TOKEN=your_token_here
SHINYAPPS_SECRET=your_secret_here

→ Deployed at https://your-account.shinyapps.io/my-app/.

If err: Auth fail → regen tokens at dashboard > Account > Tokens. Pkg install fail → CRAN only default, not GitHub.

Step 2b: Posit Connect

# Register server (one-time)
rsconnect::addServer(
  url = "https://connect.example.com",
  name = "production"
)

# Authenticate (one-time)
rsconnect::connectApiUser(
  account = "your-username",
  server = "production",
  apiKey = Sys.getenv("CONNECT_API_KEY")
)

# Deploy
rsconnect::deployApp(
  appDir = "path/to/app",
  appName = "my-app",
  server = "production",
  account = "your-username"
)

→ Deployed on Connect instance.

If err: Server rejects → verify API key + URL. Pkg install fail → check Connect repo access (CRAN, internal).

Step 2c: Docker

Dockerfile:

FROM rocker/shiny-verse:4.4.0

# Install system dependencies
RUN apt-get update && apt-get install -y \
    libcurl4-openssl-dev \
    libssl-dev \
    libxml2-dev \
    && rm -rf /var/lib/apt/lists/*

# Install R packages
RUN R -e "install.packages(c('shiny', 'bslib', 'DT', 'plotly'))"

# Copy app
COPY . /srv/shiny-server/myapp/

# Configure Shiny Server
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf

# Expose port
EXPOSE 3838

# Run
CMD ["/usr/bin/shiny-server"]

shiny-server.conf:

run_as shiny;

server {
  listen 3838;

  location / {
    site_dir /srv/shiny-server/myapp;
    log_dir /var/log/shiny-server;
    directory_index on;
  }
}

Build + run:

docker build -t myapp:latest .
docker run -p 3838:3838 myapp:latest

http://localhost:3838.

If err: Build fail on pkg install → add sys libs to apt-get install. App no load → docker exec <container> cat /var/log/shiny-server/*.log.

Step 3: Verify

# Check the deployed URL responds
response <- httr::GET("https://your-app-url/")
httr::status_code(response)  # Should be 200

# For Docker
response <- httr::GET("http://localhost:3838/")
httr::status_code(response)

Manual checklist:

  1. Loads clean
  2. Interactive els respond
  3. Data conns work in prod
  4. Auth works (if applicable)

→ HTTP 200 + all features work.

If err: Server logs per platform. Common: env vars not set in prod, DB conns using localhost, local-only file paths.

Step 4: Monitoring (optional)

shinyapps.io

Dashboard: https://www.shinyapps.io/admin/#/applications.

Posit Connect

# Check deployment status via API
connectapi::connect(
  server = "https://connect.example.com",
  api_key = Sys.getenv("CONNECT_API_KEY")
)

Docker

Health check:

HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
  CMD curl -f http://localhost:3838/ || exit 1

→ Monitoring configured.

If err: Health intermittent → increase timeout. Shiny slow initial load.

Check

  • Deploys clean
  • URL HTTP 200
  • Interactive features work
  • Env vars/secrets config'd (not hardcoded)
  • Creds → .Renviron / CI secrets
  • renv.lock committed

Traps

  • Hardcoded paths: → system.file() or env vars
  • Dev-only deps: Don't deploy .Rprofile w/ mcptools::mcp_session() or devtools. Conditional load or separate profiles.
  • Missing sys libs in Docker: sf, curl, xml2 need sys libs → apt-get install
  • CRAN-only on shinyapps.io: GH pkgs need remotes + explicit install
  • Forgotten env vars: DB creds, API keys config'd in deploy env separate from code

  • scaffold-shiny-app — app structure before deploy
  • create-r-dockerfile — Docker config for R
  • setup-docker-compose — multi-container w/ DBs
  • setup-github-actions-ci — CI/CD auto deploy
  • optimize-shiny-performance — perf tune pre-prod

GitHub 仓库

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

相关推荐技能

content-collections

Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。

查看技能

polymarket

这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。

查看技能

creating-opencode-plugins

该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。

查看技能

sglang

SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。

查看技能