Understanding Packages During Deployment

Posit Connect creates Python and R package environments upon deploy to match the environment you deployed from.

When you deploy content to Posit Connect, the deployment process creates a content bundle, which includes your code and data files, as well as a list of the packages and the versions of Python and/or R your content uses. For R and sometimes for Python, the exact package versions and where they were installed from is also included.

In most cases, the package and language information in the bundle is captured automatically by the deployment process, but you will have to explicitly capture it if you are using Git-backed publishing or trying to use the rsconnect deploy manifest command.

When the content item is deployed, Posit Connect creates a standalone environment for your content to run. In this environment, Posit Connect examines the information in the bundle, matches the version of Python or R, and downloads and installs the packages that are documented.

NoteMatching Language Versions

Posit Connect automatically matches the version of Python and/or R documented in the bundle to the versions available on Posit Connect.

For more information on how the version of Python or R is determined, see the R Version Matching and Python Version Matching sections of the Admin Guide.

Since Posit Connect creates its own package environment, it must be able to find and install any private packages you’re using in your content.

Unless you are including the code from your package in the content bundle, they must be available in a location Posit Connect can also reach like GitHub or a Posit Package Manager repository.

In most cases, Posit Connect will install Python and R packages from the same location you installed them from when developing.

NoteOverriding Manifest Repositories

A Posit Connect administrator can override the Python or R repositories that appear in the manifest for a content item. They may do this, for example, to ensure that all installs come from a sanctioned internal repository. If you’re seeing packages install from an unexpected location, this is probably why.

Capturing R package dependencies

When you deploy R content, the deployment tools identify your package dependencies.

If your project uses renv and an renv.lock file is included in the deployment, the lockfile is used to enumerate the required R package dependencies. This gives you precise control over which package versions are deployed. See the how-to guide on reproducible deployments with renv for a step-by-step workflow.

If your project does not use renv, the content is analyzed to discover which packages are needed. The version of each package is determined by inspecting your active R library.

Configuring R package repositories for deployment

Posit Connect uses R package repository information captured during deployment to install packages. By default, the repositories configured on your development machine are recorded in the bundle and used by Connect.

If you use private or internal package repositories, configure them in your user or project .Rprofile:

options(repos = c(
  CRAN = "https://cran.rstudio.com/",
  mycompany = "https://rpackages.example.com/"
))

This tells R to look for packages first from CRAN and then from your company’s repository. These repositories are captured when content is deployed and used by Connect to install those same packages.

Note

.Rprofile files in content directories will govern how repositories are recorded in the bundle, but they are not used during package installation on Posit Connect, even if they are included in deployed files.

For more information about how Posit Connect resolves repositories, including administrator-configured overrides, see R package repositories in the Admin Guide.

Capturing Python package dependencies

When you deploy Python content, package dependencies must be captured in a requirements.txt file exists in your project directory. Ensure that the listed dependencies are correct for the content you are deploying.

You can generate a requirements file from your current environment:

Terminal
pip freeze > requirements.txt

Then edit it to include only the packages your content needs.

For details on the supported requirements.txt format and options, see Requirements files in the Admin Guide.

Why can’t I just directly upload my package environment to Posit Connect?

Python and R package installs work properly only with the right operating system and the right versions of Python or R. The only way for Posit Connect to ensure the package environment will function is to download and install the packages itself for the proper version of Python or R and the proper operating system.

What if my content relies on system packages?

Some Python and R packages rely on system libraries to operate. Some common examples include libraries for creating PDFs using R Markdown or Quarto, system libraries for working with geospatial data, and invoking Java using the rJava library.

Posit Connect cannot automatically download and install these system libraries.

If you are creating content that requires these system libraries, a system administrator will have to install them in the environment where Posit Connect runs.

How does the bundle know which packages I need?

For R projects using renv, the renv.lock file provides the package list directly. See Capturing R package dependencies above for details.

For R projects not using renv, the deployment process scans your code for package references. Standard ways of invoking packages are recognized:

library(pkg)
require(pkg)
pkg::function(...)

For Python content, a requirements.txt file communicates package requirements. See Capturing Python package dependencies above for details.

What if I want to self-manage the package environment on Posit Connect?

Automatic Python and R package installation can be disabled, but this is an advanced feature and requires knowledge of Python and R environment administration. It is also important to note that the same operating system requirements mentioned in the previous sections also apply when manually installing packages in your runtime environment.