Deploy to Posit Connect

Coffee and Coding

2025-07-17

Notes

  • This is a brief overview
  • Learn more in Posit Connect docs
  • Press the ‘S’ key to see speaker notes

What and why?

  • Host ‘content’ on ‘someone else’s computer’
  • Server address: https://connect.strategyunitwm.nhs.uk
  • Docs, apps, data, APIs, notebooks
  • Control access, run on schedule
  • All users see the same up-to-date content

SU examples

🔒 Login required.

Process overview

  1. Get a user account for our Posit Connect server.
  2. Write your code (push to GitHub ideally).
  3. Send file ‘bundle’ to the server.
  4. The server generates the content.
  5. Adjust content settings in the web interface (optional).
  6. Update your code and redeploy.

R demo

Simplified first-time approach (preferred):

  1. Authorise in RStudio: Tools > Global options > Publishing.
  2. Add deploy.R with rsconnect::deploy*() call.
  3. Run deploy.R without appId argument.
  4. Add deployed content ID as appId in deploy.R.
  5. Update code, re-run deploy.R.

Go to the source repo for this demo.

R demo

Example deploy.R for a Shiny app:

rsconnect::deployApp(
  appName = "coffee-test-app",
  appTitle = "Test app: Coffee and Coding",
  appFiles = c("R/", "ui.R", "server.R"),
  server = "connect.strategyunitwm.nhs.uk",
  # appId = <your deployed app's content ID>,
  lint = FALSE,
  forceUpdate = TRUE
)

Find appID in ⚙️ Settings > Info > Content ID after it’s deployed for the first time.

R demo

Example deploy.R for a Quarto doc:

rsconnect::deployDoc(
  appName = "coffee-test-doc",
  appTitle = "Test doc: Coffee and Coding",
  server = "connect.strategyunitwm.nhs.uk",
  # appId = <your deployed app's content ID>,
  lint = FALSE,
  forceUpdate = TRUE
)

Or deployApp() to specify undetected appFiles.

Python demo

  1. Install rsconnect-python package
  2. Login to Connect server with rsconnect-python in your terminal with rsconnect add --server https://connect.strategyunitwm.nhs.uk --api-key YOUR-CONNECT-API-KEY --name SU
  3. Deploy your app, following Posit Connect documentation.

You will want a requirements.txt in the root of your folder capturing the package requirements - rsconnect gets annoyed if you don’t have one.

Python demo (2)

rsconnect deploy streamlit --name SU --entrypoint app.py .

  • streamlit: Type of app I am deploying - there are other options
  • --name: Nickname that you gave the server when you logged in with the Connect server. You can check with rsconnect list in your terminal
  • --entrypoint: Name of the file containing your app. Slightly more complicated with the APIs
  • . : Files to include. I’m including all the files in my repo, otherwise the app will not run

Optional arguments:

  • --app-id: App ID on the Connect server, if you want to overwrite an existing deployment. --new if a fresh one

Web interface

There’s ‘open solo’, ‘logs’ and ‘more options’ buttons.

Panels under the ‘settings’ button are:

  • Info: e.g. adjust name, get content (app) ID
  • Access: protect with login, set vanity URL
  • Schedule: set automated re-run schedule
  • Vars: set environmental variables

⚠️ Share the direct URL, not the ‘admin view’ URL!

Web interface

Screenshot of a Shiny app with admin panels on display abvoe and to the right of the app itself. A cog icon has been selected from the top panel, exposing the settings in the right panel. Within the right panel, the 'access' section is selected, showing that anyone can access the app without a login.

Web interface

Screenshot of a Shiny app with an admin panel open at the top of the app. The logs button is selected, showing timestamped output from Posit Connect's attempt to build the app. A warning message is shown, indicating that a function from a certain package is deprecated.

Bonus round