deploy-shiny-app
About
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 publishing apps for users, moving from local development to hosting, or setting up automated deployment pipelines.
Quick Install
Claude Code
Recommendednpx 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-appCopy and paste this command in Claude Code to install this skill
Documentation
Deploy Shiny App
部署 Shiny 應用於 shinyapps.io、Posit Connect 或 Docker 容器。
適用時機
- 為外部或內部用戶發布 Shiny 應用
- 自本地開發遷至託管環境
- 為 Kubernetes 或 Docker 部署將 Shiny 應用容器化
- 設自動化部署管線
輸入
- 必需:Shiny 應用之路徑
- 必需:部署目標(shinyapps.io、Posit Connect 或 Docker)
- 可選:帳戶名與令牌(供 shinyapps.io/Connect)
- 可選:實例大小偏好
- 可選:自定網域或 URL 路徑
步驟
步驟一:備應用
確保應用自足且可部署:
# 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")
驗此等檔案存在:
app.R(或ui.R+server.R)renv.lock(建議以供可重現之部署).Rprofile於生產中不調mcptools::mcp_session()
預期: 應用於本地無誤執行,所有依賴已捕獲。
失敗時: 若 appDependencies() 報缺失套件,裝之並更 renv.lock。若應用用系統函式庫(如 gdal、curl),記之以供 Docker 路徑。
步驟二 a:部署至 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
)
將憑證存於 .Renviron(絕不於程式碼中):
# .Renviron
SHINYAPPS_TOKEN=your_token_here
SHINYAPPS_SECRET=your_secret_here
預期: 應用已部署,可於 https://your-account.shinyapps.io/my-app/ 存取。
失敗時: 若認證失敗,於 shinyapps.io 儀表板 > Account > Tokens 重生令牌。若伺服器上套件安裝失敗,查所有套件於 CRAN 可得——shinyapps.io 預設無法自 GitHub 安裝。
步驟二 b:部署至 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"
)
預期: 應用已部署,可於 Posit Connect 實例上存取。
失敗時: 若伺服器拒絕連線,驗 API 金鑰與伺服器 URL。若套件安裝失敗,查 Connect 可達所需之儲存庫(CRAN、內部類 CRAN 之儲存庫)。
步驟二 c:以 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;
}
}
建並執行:
docker build -t myapp:latest .
docker run -p 3838:3838 myapp:latest
預期: 應用於 http://localhost:3838 可達。
失敗時: 若於套件安裝時建置失敗,加缺失之系統函式庫於 apt-get install 行。若應用未載,查 Shiny Server 日誌:docker exec <container> cat /var/log/shiny-server/*.log。
步驟三:驗證部署
# 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)
人工驗證清單:
- 應用載入無誤
- 所有互動元素皆回應
- 資料連線於部署環境中運作
- 認證/授權運作(若有)
預期: 應用以 HTTP 200 回應,所有功能運作。
失敗時: 查特定部署平台之伺服器日誌。常見問題:生產中環境變數未設、資料庫連線用 localhost 而非生產 URL、或僅於本地存在之檔案路徑。
步驟四:配監控(可選)
shinyapps.io
於儀表板 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
於 Dockerfile 加健康檢查:
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD curl -f http://localhost:3838/ || exit 1
預期: 部署目標之監控已配。
失敗時: 若健康檢查間歇失敗,增超時值。Shiny 應用於初始載入時可能回應慢。
驗證
- 應用部署無誤
- 部署之 URL 以 HTTP 200 回應
- 生產中所有互動功能運作
- 環境變數/秘鑰已配(非硬編碼)
- 憑證存於
.Renviron或 CI 秘鑰,非於程式碼 - renv.lock 已提交以供可重現之依賴解析
常見陷阱
- 硬編碼檔案路徑:以
system.file()(供套件資料)或環境變數(供外部資源)替絕對路徑。 - 僅限開發之依賴:不部署載
mcptools::mcp_session()或devtools之.Rprofile。用條件載入或分離設定檔。 - Docker 中缺系統函式庫:sf、curl、xml2 等 R 套件需系統函式庫。加之於 Dockerfile 之
apt-get install。 - shinyapps.io 僅限 CRAN 套件:shinyapps.io 預設僅自 CRAN 安裝。僅限 GitHub 之套件需
remotes套件與部署中之顯式安裝。 - 遺忘環境變數:資料庫憑證、API 金鑰等秘鑰須於部署環境中與程式碼分離地配置。
相關技能
scaffold-shiny-app— 部署前建應用結構create-r-dockerfile— R 專案之詳細 Docker 配置setup-docker-compose— Shiny 與資料庫之多容器設定setup-github-actions-ci— 含自動化部署之 CI/CDoptimize-shiny-performance— 部署至生產前之性能調優
GitHub Repository
Related Skills
content-collections
MetaThis 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.
polymarket
MetaThis 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.
creating-opencode-plugins
MetaThis 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.
sglang
MetaSGLang 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.
