
How to Programmatically Clone and Deploy the RPACT Cloud Shiny App to Posit Connect
12 November, 2025 11:49:43
Source:vignettes/deploy-programmatically-to-posit-connect.Rmd
deploy-programmatically-to-posit-connect.RmdThis guide shows you how to programmatically:
- Clone the RPACT Cloud Shiny application from the GitHub repository.
-
Install all necessary dependencies (as defined in
the
DESCRIPTIONfile). - Configure Posit Connect credentials.
- Deploy to Posit Connect (formerly RStudio Connect) using the rsconnect R package.
All steps are presented in a typical R script format to help you automate the process. For user/company-specific information (Posit Connect URL, credentials, etc.), see the detailed instructions under Step 3.
Note: The steps below assume you have already installed Git, R, and the necessary R packages (
usethis,rsconnect), and you have created a Posit Connect API key to authenticate against your Posit Connect server.
Step 1: Clone the RPACT Cloud Repository (Private)
Because the repository is private, you need to provide a GitHub
Personal Access Token (PAT) or alternative authentication. Below is an
example using a PAT inline in the git clone command
(not recommended for production scripts, but shown here
for clarity). A more secure approach is to set it as an environment
variable.
Option A: Inline Personal Access Token (for demonstration)
# Step 1: Clone the repository (private)
# --------------------------------------
# Replace <YOUR_GITHUB_PAT> with your actual Personal Access Token
# and make sure it has permissions to read private repos.
system("git clone https://<YOUR_GITHUB_PAT>@github.com/rpact-com/rpact.cloud.git")Warning: This method will expose your PAT in plain text in your code, logs, or command history. Use it only if you understand the security risks.
Option B: Using Environment Variables (recommended)
# Step 1: Clone the repository (private) securely
# -----------------------------------------------
# 1. Set your GitHub token as an environment variable (e.g., in .Renviron or this script)
Sys.setenv(GITHUB_PAT = "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN")
# 2. Use the environment variable in the clone command
token <- Sys.getenv("GITHUB_PAT")
# 3. Construct a secure clone URL
# (Note the use of paste0 to build the URL; token is not directly revealed in the script)
clone_url <- paste0("https://", token, "@github.com/rpact-com/rpact.cloud.git")
system(paste("git clone", clone_url))After running this, you will have a local folder named
rpact.cloud which contains the R Shiny app code and a
DESCRIPTION file.
Step 2: Install Dependencies from the DESCRIPTION File
RPACT Cloud has a DESCRIPTION file that specifies the
required packages. You can programmatically install these dependencies
using the remotes (or devtools)
package.
Below is an example using remotes:
# Step 2: Install dependencies
# ----------------------------
# Install 'remotes' if it's not already installed
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
# Load 'remotes' and install dependencies from the DESCRIPTION file
library(remotes)
# Replace "rpact.cloud" with the path to your cloned repository if necessary
install_deps("rpact.cloud", dependencies = TRUE)Step 3: Configure Your Posit Connect Credentials
Before deploying, you need to configure your user or company-specific settings for Posit Connect. This includes:
- Your Posit Connect server URL,
- Your account name (as recognized by Posit Connect),
- Your token and secret (from your Posit Connect API key), or
- Other credential methods supported by
rsconnect.
Typically, you will use one of the following methods to set your credentials:
Method A: Using rsconnect::setAccountInfo()
# Step 3: Set Posit Connect account information
# ---------------------------------------------
library(rsconnect)
# Replace the placeholders with your actual data:
# "myAccount" = the account name on Posit Connect
# "myToken" = the token from your Posit Connect account
# "mySecret" = the secret from your Posit Connect account
# "https://connect.company.com/" = your Posit Connect server URL
rsconnect::setAccountInfo(
name = "myAccount",
token = "myToken",
secret = "mySecret",
server = "https://connect.company.com/"
)Method B: Using Environment Variables
You can also store your credentials in environment variables for
added security. You might place them in an .Renviron file
or set them inline in your script before deployment. For example:
# In an .Renviron file (key-value pairs, no quotes):
# CONNECT_API_KEY=myToken
# CONNECT_API_SECRET=mySecret
# CONNECT_SERVER=https://connect.company.com
# CONNECT_ACCOUNT_NAME=myAccount
# Step 3 (alternative): Setting your environment variables
Sys.setenv(
CONNECT_API_KEY = "myToken",
CONNECT_API_SECRET = "mySecret",
CONNECT_SERVER = "https://connect.company.com",
CONNECT_ACCOUNT_NAME = "myAccount")
# Then reference these environment variables in your code
rsconnect::setAccountInfo(
name = Sys.getenv("CONNECT_ACCOUNT_NAME"),
token = Sys.getenv("CONNECT_API_KEY"),
secret = Sys.getenv("CONNECT_API_SECRET"),
server = Sys.getenv("CONNECT_SERVER")
)Important: Ensure your tokens, secrets, and other sensitive data are never committed to version control (such as GitHub). Use .gitignore or environment variables to keep them private.
Step 4: Deploy the App Using rsconnect
Now that your environment is set, navigate to the folder containing
the cloned app and deploy. Typically, deployApp() is run
from within the directory containing the Shiny app’s app.R
or other deployment files.
# Step 4: Deploy the RPACT Cloud App
# ----------------------------------
library(rsconnect)
# Assuming the app is in the "./rpact.cloud" directory:
rsconnect::deployApp(
appDir = "rpact.cloud", # Path to the application directory
account = "myAccount", # Or use Sys.getenv("CONNECT_ACCOUNT_NAME")
server = "connect.company.com", # Or your chosen server alias if set
appName = "RPACT_Cloud_App", # Name the app on Posit Connect
appTitle = "RPACT Cloud", # Title displayed on Posit Connect
forceUpdate = TRUE # Update an existing app if it already exists
)After a successful deployment, you can visit the assigned URL on your Posit Connect server to access the newly deployed RPACT Cloud Shiny app.
Summary
- Clone the GitHub repository locally.
- Configure your Posit Connect server URL and account credentials in R
(using
rsconnect::setAccountInfo()or environment variables). - Deploy your Shiny app with
rsconnect::deployApp().
By following these steps in an R script, you can automate the entire clone-and-deploy process for RPACT Cloud. Be sure to adapt all placeholders (server URL, account name, token, secret) to match your specific company or personal Posit Connect environment.