Git-backed deployment in Posit Connect

Pushing to Git updates your code. With Git-backed deployment on Posit Connect, it automatically updates your published content too.
2023-02-06
The Posit Connect logo and the Git logo with a circular arrow in between

Vedha Viyash is an R enthusiast and R/Shiny developer at Appsilon. His passion is unlocking the potential of open-source data to generate actionable insights. He focuses on using R, Tidyverse, SQL, REST APIs, CSS, and JS to create dynamic dashboards with Shiny. His work in the life sciences includes applications for lung transplant, oncology, genomics, and toxicity fields.

Shiny is a tool that’s hard to beat when building Data Science applications at speed. The Time to Value that Shiny apps offer makes them suitable for building minimal viable products (MVPs). Shiny’s Proof of Value makes it easier to get stakeholder buy-in for more demanding projects down the line. Most of the companies that use Shiny rely on these traits to prove concepts and project value.

The release of Shiny for Python (alpha now) opens up new possibilities for data scientists and developers who are more comfortable using Python to get access to the same powerful framework to create interactive data science web apps.

Shiny also has an arsenal of deployment options to choose from. No matter the budget or scope of the project, there is a solution appropriate for your needs. Ultimately, making seamless and quick deployment ensures you focus on building apps rather than trying to deploy them.

Posit helps developers maximize this with products like Connect and features like Git-backed deployment.

 

Shiny deployment options

 

Within Posit’s suite of deployment options, you can find 3 choices to match 3 types of project needs.

There’s shinyapps.io with zero hardware/installation/purchase contract, which is perfect for exploratory projects or independent developers.

Shiny Server if you want to deploy your Shiny app on your own server.

Posit Connect (RStudio Connect) if you’re serious about upgrading and scaling the data science capabilities of your team.

Irrespective of the deployment mode that you choose, deploying your Shiny apps is just a few clicks away. Posit simplifies the process of giving life to your Shiny ideas so you can focus on your project.

 

Posit Connect and Git-backed deployment

 

Here, we will go into one particular feature offered in Posit Connect, which can help you streamline the deployment workflow!

Even if the deployment actions are simple, they’re still a click away. Automating this last step could be beneficial as it removes a human element from the equation.

This is exactly what Git-backed deployment offers.

When an app is deployed using Git-backed deployment, you can be sure that the deployed application is always up-to-date with the latest code. Now you can sleep at night, not wondering if you deployed your app after making all those new changes.

 

What is Git-backed deployment?

 

Git-backed deployment in Posit Connect refers to a way of deploying Shiny applications, R Markdown/Quarto documents, or other types of content that are stored in a Git repository. Git allows you to easily version control your content, collaborate with others on your team, and track the changes that have been made over time.

When you deploy your content from a Git repository, Posit Connect will automatically pull the latest version from the repository and publish it on the server. This makes it easy to keep your published content up-to-date and ensures that you are always working with the latest version.

 

Prerequisites for using Git-backed deployment in Posit Connect

 

If your project uses a private Git repository, you should make sure that you give the repository access to a Git account that is configured in your Posit Connect.

In the image below, you’ll see two configuration pop-ups. On the left, you can see that the Connect is not configured with a Git account, and on the right, you can see that it is configured with a Git account, “appsilon-bot”.

 

Popup for creating new content from a Git repository on Connect.

 

If your Connect account is not configured with a Git account, you might need some IT help from your organization. Check the admin guide to see how to set this up properly.

 

Steps to auto-deploy apps using Git-backed deployment in Posit Connect

 

Now that you have your Git account authenticated, follow these next steps to set up the Continuous Git-backed Deployment.

 

Step 1: Create the manifest.json

 

The manifest.json contains information that helps Posit Connect (previously RStudio Connect) in deploying and hosting your content.

Note that the manifest.json file needs to be updated when committing your changes, and want the deployed app in Posit Connect to be updated.

For an R-based Shiny app

Make sure that you have installed the rsconnect package.

install.packages('rsconnect')

Now you can use the following command to create/update the manifest.json in your app’s working directory using the following command.

rsconnect::writeManifest()

For a Python-based Shiny app

You will also need a newer Posit Connect/RStudio Connect, any version above 2022.08.0 should be fine. Make sure that you have installed rsconnect-python. You can install it using pip.

pip install rsconnect-python

Now you can use the following command to create/update the manifest.json in your app’s root directory.

rsconnect write-manifest shiny .

 

Step 2: Click through Posit Connect

 

Posit makes using Git-backed deployment a piece of cake. Their guided setup takes just a few button clicks.

Choose the Import from Git as the publishing method.

 

Import from Git option on the publishing list on Connect.

 

Now you can paste the URL of the Git Repository and click Next.

 

New content from Git repo pop up

 

 

Branch selection

 

Now, select the branch you wish to trigger the automatic deployment and click Next.

 

Branch selection pop up

 

Common deployment error

 

If you stumble upon this error in the next step, the branch you selected does not contain the manifest.json as detailed in the error message. You should run rsconnect::writeManifest() and generate the manifest.json and do the previous step again.

 

No deployable content was found error message

 

Set deployment

 

If your repository contains multiple manifest.json, you need to select the required manifest.json, add a title for the content, and deploy it for the first time.

 

New content from Git repository pop up with the root directory chosen as the directory with the manifest.json file.

 

After clicking the Deploy Content, you should see the progress of the deployment, after which you can open and view the deployed app.

 

New content from Git repository popup with progress showing.

 

Updating options – manual and automated

 

In the Info tab of the deployed app’s Posit Connect page, you may manually update the app using the Update Now button. You may also choose to check for new changes to the manifest.json in the repository to automatically deploy the app.

 

Info tab with 'check for updates periodically' checked.

Info tab for content generated with Git with check for updates periodically checked.

 

Closing out automated Shiny deployment with Posit Connect

 

It really is as simple as that. You now have an application that will remain up-to-date with the latest code. You can rest assured knowing your app contains the latest updates and remove “move to deployment” from your task list. 

There are a lot of interesting and helpful features for Shiny developers in Posit Connect. If you’re working on R and Python projects across teams, we recommend you check out Posit Package Manager next. It’s a strong tool for centralizing and managing packages for your organization. Avoid issues like the Isoband Incident and ensure your project stays reliable, secure, and compliant with Package Manager.

 

Learn more