Topics Map > Data Science Platform

Git-Backed & CLI Publishing on Connect

Content from a remote Git repository can be deployed directly to Posit Connect. Once published, the content automatically fetches from the associated remote Git repository and re-deploys. This feature supports Git-centric workflows and continuous deployment automation. This document describes how to publish an artifact (Shiny application, R Markdown document, plot, graph, website, Jupyter Notebook, Plumber API, or Quarto document) from a Git Repository to Posit Connect.

Two Step Process for Deploying Git-Backed Content

  1. Create and commit a manifest file in the development environment.
  2. Link Connect to the Git repository from within Connect.

Create Manifest from R

The `manifest.json` file must be associated specifically with the content that you want Connect to track and deploy. This file contains information used by Connect that tell it how to deploy and host the content. This file can be created with the R function `rsconnect::writeManifest()`.

This function does its best to infer the correct information about the content to be published, but in some cases may need further specifications through function arguments.

  • `appDir`: The directory containing the application in cases where there are multiple content pieces in children directories.
  • `appPrimaryDoc`: The primary file in cases where there are more then one.
  • `contentCategory`: The type of content in cases where it is unclear.

Create Manifest from Python CLI

First install the latest version of the `rsconnect-python` package from pip: `pip install rsconnect-python`

Once installed, use the `write-manifest` command to create a manifest for your specific Python content type. When the command is run it searches for a `requirements.txt` file in the source directory. If not found, the tool inspects the existing Python environment and creates the file for you (be sure to activate your virtual environment to ensure that the requirements are found by the command).

An example of using the Python CLI to write the `manifest.json` file might look like this:

`rsconnect write-manifest notebook my-notebook.ipynb`

Linking Git to Posit Connect

The second step of the process takes place in Connect. You must have publisher rights on Connect for this to work.

On the "Content Listing" page of Connect click the publish button and select the "Import from Git" option. Provide the https address from your git repository, select the desired branch, and then select the target directory. Each directory that contains a `manifest.json` file will show up in the drop down list of directories. Once the directory is selected the file will begin deployment and you can open the published version from the window.

To Learn More...

Visit the Posit Documentation for additional details.

Git-Backed Publishing: https://docs.posit.co/connect/user/git-backed/

Publishing Directly from Command Line Interface

Posit Connect supports CLI deployment of Jupyter Notebook, Python APIs (Flask or FastAPI), and apps (Dash, Streamlit, Shiny for Python, and Bokeh apps).

Other content types not supported by CLI can be deployed with CLI so long as they have a prepared `manifest.json` file.

Create API Key on Connect

Navigate to the Posit Connect Dashboard, and open your profile. You will see an option to access API keys. Create one here and copy it to your clipboard. Treat this API key as you would your password.

To learn how to securely manage sensitive informatiom within RStudio, you can read this: https://cran.r-project.org/web/packages/httr/vignettes/secrets.html.

Install `rsconnect-python`

You must first install rsconnect-python command line interface in the virtual environment for your project using pip:

`pip install rsconnect-python`

Adding Connect Server

To add a server, you need the following:

  1. Your server URL (--server / -s)
  2. Your API key (--api-key / -k).
  3. A nickname for the server that you provide (--name/ -n)

`rsconnect add --server https://my.connect.server/ --name myServer --api-key $CONNECT_API_KEY`

Deployment

Using the `rsconnect deploy` command, you can deploy your content to Connect server you added in the step above.

To deploy with a particular title, use the `--title` option:

`rsconnect deploy notebook --title "My Notebook" my-notebook.ipynb`

To deploy with environment variables:

`rsconnect deploy notebook --environment MYVAR='hello world' notebook.ipynb`

To Learn More...

Visit the Posit Documentation for additional details.

Git-Backed Publishing: <https://docs.posit.co/connect/user/publishing-cli/>



Keywords:
Gitlab Github Connect Publishing 
Doc ID:
146983
Owned by:
Spencer B. in UW-Madison Research Data
Created:
2024-12-16
Updated:
2025-03-03
Sites:
DoIT Help Desk, UW-Madison Research Data