Publishing from R

This section describes how to publish content to Posit Connect from R. This can be done from the RStudio IDE’s R Console as an alternative to push-button publishing, or for content types or options that do not support push-button publishing. You can also use this method to publish from R session in a terminal outside of the RStudio IDE.

This workflow uses the rsconnect R package. See the rsconnect documentation or the package help for details.

Shiny Applications

To publish a Shiny application, use the deployApp function, specifying your project’s directory:

rsconnect::deployApp(appDir = '<project-dir>')

For more information:

install.packages('rsconnect')
library(rsconnect)
?rsconnect::deployApp

Plumber APIs

To get started with publishing Plumber API endpoints, create a directory with a plumber.R file defining your endpoints. From the R console, execute the following, replacing <project-dir> with your project’s directory:

rsconnect::deployAPI(api = '<project-dir>')

Quarto Content

The rsconnect package can deploy all Quarto content supported by Posit Connect (Quarto support is included in version 0.8.26).

To use rsconnect::deployApp() to deploy Quarto content, you need to pass the path to a Quarto binary to function’s quarto argument:

rsconnect::deployApp(appDir, quarto = "path/to/quarto")

If Quarto is available on your PATH, you can use "quarto". If this doesn’t work, you can use the function quarto_path() from the quarto package:

rsconnect::deployApp(quarto = quarto::quarto_path())

The function rsconnect::writeManifest() can also generate manifests for Quarto content when provided a quarto argument.

Specifying a Target Image

If your Posit Connect installation uses off-host content execution with Kubernetes, Connect will automatically select an appropriate image to use when building or running your content. However, you can also specify a different image if you prefer, by providing the image argument when writing a manifest or deploying:

rsconnect::writeManifest(...,
    image = "ghcr.io/rstudio/content-base:r4.0.5-py3.8.8-jammy")
rsconnect::deployApp(...,
    image = "ghcr.io/rstudio/content-base:r4.0.5-py3.8.8-jammy")
rsconnect::deployAPI(...,
    image = "ghcr.io/rstudio/content-base:r4.0.5-py3.8.8-jammy")
rsconnect::deployDoc(...,
    image = "ghcr.io/rstudio/content-base:r4.0.5-py3.8.8-jammy")
rsconnect::deploySite(...,
    image = "ghcr.io/rstudio/content-base:r4.0.5-py3.8.8-jammy")

You may only use an image that has been configured by your administrator. You can see a list of available images by logging in to Posit Connect and clicking the Environments button at the top of the page.

If the image you select does not contain appropriate R, Python, or Quarto versions for the content you are deploying, the deployment will fail.

At any time, you may redeploy content without specifying an image (or write a manifest without specifying an image, and deploy the manifest) to go back to allowing Posit Connect to choose an image automatically.

Note

Push-button publishing does not support selecting a specific content image at this time.

Specifying an environment management strategy

Note

Note that the environment management features used in this guide are also applicable for Posit Connect’s native execution mode. Off-host execution is not required to use the R and Python environment management features.

Sometimes it is preferable to self-manage R package installation for your system, rather than allowing Posit Connect to install packages for you. This can be useful in situations where many pieces of content share the same set of packages, or if off-host execution is enabled and the packages are already installed in the execution environment image.

rsconnect::writeManifest(..., envManagementR = FALSE)
rsconnect::deployApp(..., envManagementR = FALSE)
rsconnect::deployAPI(..., envManagementR = FALSE)
rsconnect::deployDoc(..., envManagementR = FALSE)
rsconnect::deploySite(..., envManagementR = FALSE)

When environment management is disabled, Connect uses only the packages that are already installed in the system library, no new packages are installed during the deployment. It is up to your administrator to install the required packages in the system library so that they are available for your content at runtime.

At any time, you may redeploy content without specifying an environment management strategy (or write a manifest without specifying, and deploy the manifest) to go back to allowing Posit Connect to choose an environment management strategy based on the application-level and server-level defaults.

Note

Push-button publishing does not support selecting an environment management strategy at this time.