Lab 5 – Setting up Repositories and deploying content to Connect
The developers of the content that will be deployed on Connect, whether they use R or Python, rely on packages and libraries that are distributed by repositories such as CRAN and PyPi respectively. As an Administrator of Connect you can configure the repositories used and other factors such as the format (source or binary) in which the packages will be downloaded.
- Reading time: 10 minutes
- Documentation reading time: 35-45 minutes
- Hands-on exercise time: 20-30 minutes
R package management
When developing content in R, developers rely on packages. These packages are hosted in repositories. The most popular repository is called CRAN and there are multiple mirrors hosting its content. Another popular repository is Bioconductor. Additionally, enterprises might host their own repositories with private packages or approved subsets of CRAN for instance. When developers deploy content to Connect, the repositories used to download the packages is recorded and uploaded to Connect.
However, as an administrator you can configure the Connect server to complement the repositories used by the developers or to ignore them.
- By setting
R.PackageRepositoryResolution = "lax", the list of repositories used by the developer and the list from the Connect configuration file are merged, with the list from the Connect configuration taking precedence. - By setting
R.PackageRepositoryResolution = "strict", the list of repositories used by the developer is ignored, and only repositories listed in the Connect configuration file are used. To make sure that content deploy successfully when using this setting, your developers need to use the same repositories in their development environment. This setting is only recommended in security conscious environments.
Posit Package Manager is a repository management solution that makes it easy to centralize the management of the R packages and Python libraries used by your developers. Posit Package Manager integrates with Connect. There is a publicly available version of Package Manager that you can use. If you purchase a license for Package Manager, you can have an offline version of CRAN (useful for air gapped environments), curate the list of approved packages in your organization, and host private packages. Both build binary versions of the R packages for Linux distributions speeding up content deployment as packages do not need to be compiled during deployment. Connect provides options to control the installation of binary versions of the packages.
For this lab, you are going to configure Connect to use the public version of Posit Package Manager as the “CRAN” repository to serve binary versions of the R packages. With this setting, your deployments will be fast as the packages won’t need to be compiled, but if your developers used repositories outside of CRAN for their development, the deployment will still succeed.
Based on your reading of the documentation, what do you need to add to your configuration file?
- Go to the Setup page of Package Manager
- Select “Linux” for the Operating System
- Choose “Ubuntu 24.04 (Noble)” for the Linux Distribution
- For Snapshots, choose “No, install the most recent package available”
- Under Environment, choose “Posit Connect”
- Copy the configuration snippet under Setup Instructions
- Note that you installed many of the System Requirements listed at the bottom of the page.
- Open Connect’s configuration file (
/etc/rstudio-connect/rstudio-connect.gcfg) and Paste the configuration entry. - Restart Connect.
Python
Connect gives administrators control over how the Python environments are managed. By default, Connect manages the Python environments and uses a pip to retrieve the libraries needed to deploy the applications.
Since Connect uses pip, you can configure it globally by editing the file /etc/pip.conf. For instance, you can replace the default PyPI repository with Posit Package Manager’s.
To do so, create the file /etc/pip.conf so it contains:
[global]
timeout = 60
index-url = https://packagemanager.posit.co/pypi/latest/simple
trusted-host = packagemanager.posit.coWith this configuration, pip will retrieve Python libraries from the public version of Posit Package Manager.
Now that you updated its configuration, make sure you restart Connect with:
sudo systemctl restart rstudio-connect.serviceDeploying Content
You are now ready to deploy content to Connect. There are several ways of deploying Content, but for the purpose of this lab, we are going to use the Connect Gallery. The Gallery, introduced in Connect 2025.05, is a collection of assets that can be deployed on a Connect server. They are hosted on GitHub and do not require any coding or any set up. This provides an easy mechanism to make sure that your installation of Connect is ready to deploy content from your users.
Navigate to the “Posit Connect” tab, and click on “Log in”. You can log in as any one of the users listed previously that have at least Publisher privileges such as “elena.rodriguez” (as a reminder, their password is the same as their user name).
Once you are logged in, go to the “Gallery” tab within Connect. There, navigate to the “Examples” section, and click on the “Add” button for the “Quarto Stock Report using R”.
It takes a few minutes to deploy this content. You can check the logs for the deployment of this report by navigating to the “Content” link in the navigation bar. To see content that has not yet been published, you can type: “not:published” in the search bar. You should see an entry listed as “extension-XXXXXXXXXXX” in the list that appears. Click on that name. In the new page that appears, click on “Bundles” in the top right corner. Click on the date/time entry listed in the modal, and the “View Log” link below. The deployment log for this application is then displayed, and you can check that Connect is correctly downloading the R binary packages from Package Manager.
Towards the beginning of the logs, you should see something like:
Packages will be installed using the following repositories:
- CRAN = "https://packagemanager.posit.co/cran/__linux__/noble/latest"
- CRAN.1 = "https://cloud.r-project.org"
indicating that the repository serving binary packages from Package Manager is configured correctly as it takes precedence on the CRAN repository configured in the source code of the content being deployed.
Additionally, when installing packages, you should see output indicating that binary packages are being installed (notice the word binary in the output):
Caching MASS.
Using cached MASS.
OK (downloaded binary)
Once all the report is successfully deployed, you can click the “Check” button to verify that you completed all the steps for this lab.
Check Your Understanding
After completing this lab, you should be able to answer the following questions:
Repository Configuration: What is the difference between setting
R.PackageRepositoryResolution = "lax"versusR.PackageRepositoryResolution = "strict"in Connect’s configuration? When would you use each setting?Package Manager Integration: What are the main benefits of using Posit Package Manager with Connect, and how does the
PositPackageManagerURLRewriting = "force-binary"setting improve deployment performance?
Looking back, Planning ahead
Based on what you learned, ask your team:
- Which repositories do you want to enable in Connect for R and Python?