deploy-shiny-app
关于
This Claude Skill helps developers deploy Shiny applications to shinyapps.io, Posit Connect, or Docker containers. It handles configuration, manifest generation, Dockerfile creation, and deployment verification. Use it when moving from local development to a hosted environment or setting up automated deployment pipelines.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/deploy-shiny-app在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Deploy Shiny App
Deploy Shiny application to shinyapps.io, Posit Connect, or Docker container.
When Use
- Publish Shiny app for external or internal users
- Move from local development to hosted environment
- Containerize Shiny app for Kubernetes or Docker deployment
- Set up automated deployment pipelines
Inputs
- Required: Path to Shiny application
- Required: Deployment target (shinyapps.io, Posit Connect, or Docker)
- Optional: Account name and token (for shinyapps.io/Connect)
- Optional: Instance size preference
- Optional: Custom domain or URL path
Steps
Step 1: Prep Application
Ensure app is self-contained and deployable:
# Check for missing dependencies
rsconnect::appDependencies("path/to/app")
# For golem apps, ensure DESCRIPTION lists all Imports
devtools::check()
# Verify app runs cleanly
shiny::runApp("path/to/app")
Verify these files exist:
app.R(orui.R+server.R)renv.lock(recommended for reproducible deployments).Rprofiledoes NOT callmcptools::mcp_session()in production
Got: App runs locally without errors. All dependencies captured.
If fail: If appDependencies() reports missing packages, install them and update renv.lock. If app uses system libraries (e.g., gdal, curl), note them for Docker path.
Step 2a: Deploy to 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
)
Store credentials in .Renviron (never in code):
# .Renviron
SHINYAPPS_TOKEN=your_token_here
SHINYAPPS_SECRET=your_secret_here
Got: App deployed and accessible at https://your-account.shinyapps.io/my-app/.
If fail: If authentication fails, regenerate tokens at shinyapps.io dashboard > Account > Tokens. If package installation fails on server, check all packages available on CRAN — shinyapps.io cannot install from GitHub by default.
Step 2b: Deploy to 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"
)
Got: App deployed and accessible on Posit Connect instance.
If fail: If server rejects connection, verify API key and server URL. If packages fail to install, check Connect has access to required repositories (CRAN, internal CRAN-like repos).
Step 2c: Deploy with Docker
Create 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"]
Create 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 and run:
docker build -t myapp:latest .
docker run -p 3838:3838 myapp:latest
Got: App accessible at http://localhost:3838.
If fail: If build fails on package installation, add missing system libraries to apt-get install line. If app doesn't load, check Shiny Server logs: docker exec <container> cat /var/log/shiny-server/*.log.
Step 3: Verify Deployment
# Check 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 verification checklist:
- App loads without errors
- All interactive elements respond
- Data connections work in deployed environment
- Authentication/authorization works (if applicable)
Got: App responds with HTTP 200. All features work.
If fail: Check server logs for specific deployment platform. Common issues: environment variables not set in production, database connections using localhost instead of production URLs, or file paths only existing locally.
Step 4: Configure Monitoring (Optional)
shinyapps.io
Monitor via dashboard at 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
Add health check to Dockerfile:
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD curl -f http://localhost:3838/ || exit 1
Got: Monitoring configured for deployment target.
If fail: If health checks fail intermittently, increase timeout values. Shiny apps can be slow to respond during initial load.
Checks
- App deploys without errors
- Deployed URL responds with HTTP 200
- All interactive features work in production
- Environment variables/secrets configured (not hardcoded)
- Credentials stored in
.Renvironor CI secrets, not in code - renv.lock committed for reproducible dependency resolution
Pitfalls
- Hardcoded file paths: Replace absolute paths with
system.file()(for package data) or environment variables (for external resources). - Development-only dependencies: Don't deploy
.Rprofilethat loadsmcptools::mcp_session()ordevtools. Use conditional loading or separate profiles. - Missing system libraries in Docker: R packages like sf, curl, and xml2 need system libraries. Add them to Dockerfile's
apt-get install. - CRAN-only packages on shinyapps.io: shinyapps.io only installs from CRAN by default. GitHub-only packages need
remotespackage and explicit installation in deployment. - Forgotten environment variables: Database credentials, API keys, other secrets must be configured in deployment environment separately from code.
See Also
scaffold-shiny-app— create app structure before deploymentcreate-r-dockerfile— detailed Docker configuration for R projectssetup-docker-compose— multi-container setups for Shiny with databasessetup-github-actions-ci— CI/CD including automated deploymentoptimize-shiny-performance— performance tuning before deploying to production
GitHub 仓库
相关推荐技能
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是理想选择。
