Resources

Deploying a Shiny for Python application with Posit Connect

video
May 2, 2023
2:47

image: thumbnail.jpg

Transcript#

This transcript was generated automatically and may contain errors.

In this short video, we'll go through the process of deploying a Shiny for Python application from Posit Workbench, here I am in VS Code, to Posit Connect. So just to give you a lay of the land, so what you're seeing right here is a Shiny for Python application called app.py, and that resides in a directory I've created called Shiny for Python.

Installing packages

So to get started, let's go ahead and install some packages we'll need for this workflow. So I'm going to use pip to install the Shiny package. Also rsconnect Python, which is used to deploy applications to connect. And then you can see this application depends on two popular data science packages, matplotlib and numpy. So let's make sure we install those as well.

I believe I already have these in my environment. So it should say requirement already satisfied. So that's great, we are in a good spot. Now before we deploy to Posit Connect, let's just make sure this application runs correctly locally here within VS Code running on Posit Workbench.

Running the app locally

So I'll run shiny run and the name of the file app.py, hit enter.

And we'll get a URL that I can then click on. And here is our Shiny for Python application. It's a simple slider bar that changes the number of bins in the histogram as I move it left and right. Alright, so it appears to be working well.

Deploying to Posit Connect

And then the last thing we'll do is go ahead and deploy it to Posit Connect. And we'll use the rsconnect package to help with this. So rsconnect deploy shiny, you have to give it the name of the connect server you want to deploy to. So I'll use the dash n argument. And I have the server saved my environment as PCT prod. And then just give it the name of the directory that houses the app.py file. I'm currently within this directory. So I'll just use the period as a shorthand and hit enter.

It'll run through a few checks, make sure my environment is being captured and recorded and sent to connect to replicate that environment. And once that is done, it'll deploy to Posit Connect and we'll get two URLs here at the bottom, I can click on this bottom one and it will actually bring me straight to Posit Connect. And here we have that same application running on the connect instance. And that is how you can deploy a Shiny for Python application to Posit Connect.