Skip to content

Programmatic Deployment via APIs#

As data products become critical to organizations, RStudio Connect users have requested more flexible deployment options. Enterprise workflows sometimes require approvals to publish to production environments. For example, content stored in Git may be published to separate QA or Production environments based on IT approvals.

Starting in RStudio Connect 1.7.0, we've added support for programmatic deployment in the RStudio Connect Server API. These new APIs let your deployment engineers craft custom deployment workflows.

Important: As of the RStudio Connect release 1.7.0, all content management API endpoints are listed as experimental and could be subject to alteration in future releases.

Getting Started: Recipes and Resources#

Workflow Expectations#

Whether you already have an automated testing and deployment system in place or you're starting from scratch, it's important to understand the sequence of events that are required for content deployment, and how those events map to the APIs.

The process can be broken down into the series of steps represented here:

On the left you'll see tasks that an R user would perform. They are responsible for:

  • Creating or updating the content
  • Generating or updating the content manifest file
  • (optional) Committing the project to a centralized version control system

The right side of the diagram depicts steps that involve the RStudio Connect content management APIs. These are the steps that you'll likely want to automate.

Note: Interacting with the content management APIs as described below, first requires creating an [API key]( from a publisher or administrator account on RStudio Connect.

Step 1: Content placeholder creation

The /content endpoint is used to create a new placeholder item on the target Connect server.

This action returns a globally unique identifier (GUID) assigned to the created content item. The GUID becomes an argument to input in the following endpoints, and will exist throughout the lifecycle of the content item (until deleted).

Step 2: Upload a bundle

The /content/{guid}/upload endpoint is used to upload a new deployment bundle.

Bundles must be gzip compressed tar archives, and they must include a manifest.json file as created by the R user or deployment engineer. The manifest file describes the content requirements and is generated with the rsconnect package in R:



Publishers with collaborator rights to this content (including the owner) are permitted to upload deployment bundles. Users without these rights are rejected. Administrators must be a collaborator for a content item before they receive upload rights.

A bundle for a Shiny application includes an app.R or ui.R and server.R files, and any images or data files required by the application. An R Markdown document bundle includes the index.Rmd file along with any R scripts and data files needed to render the report.

Example of using tar to create an archive for a Shiny application:

tar zcf bundle.tar.gz ./manifest.json ./app.R ./www/logo.png

Step 3: Deploy a bundle

The /content/{guid}/deploy endpoint is used to activate a deployment bundle on the server.

Deployment requests spawn an asynchronous task to make your previously uploaded data available for serving. The workflow applied to the bundled files varies depending on the type of content. The response from this endpoint includes a task identifier. Poll the GET /tasks/{id} endpoint to track the progress of deployment.

Additional Resources:#

CI/CD Integration Examples#

GitHub and Travis CI#

Travis CI integrates directly with GitHub repositories and can trigger the automatic deployment of content to RStudio Connect.

Travis supports 'branch build workflows' and 'pull request build workflows'. Learn more about Travis CI here.

Example Project: Automatic deployment of a Shiny app to an instance of RStudio Connect

GitHub Webhooks and Jenkins#

Jenkins is an open source automation server which provides hundreds of plugins, including GitHub integration.

How-To Guide: RStudio Connect Deployments with GitHub Webhooks and Jenkins Freestyle