
Deploying a Python application with Posit Connect
Posit Connect is our flagship publishing platform for data products built in R and Python. Learn more: https://posit.co/products/enterprise/connect/ Book a demo of Connect: https://posit.co/schedule-a-call/?booking_calendar__c=RSC_YT_Demo With Connect, you can deploy, manage, and share your R and Python content, including Shiny applications, Dash, Streamlit, and Voilà applications, R Markdown reports, Jupyter Notebooks, Quarto documents, dashboards, APIs (Plumber, Flask), and more. Give stakeholders authenticated access to the content they need, and schedule reports to update automatically
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
the next step, which is really the last step. We are going to go ahead and deploy this application using the RSConnect Python package. Now there's a note right here. You will need to create and use an API key in order to deploy your Python application. This is important because when you deploy to Posit Connect using this package, the RSConnect Python package, Connect needs to know who's actually trying to deploy and make sure you have the necessary credentials and the privileges to actually deploy to that instance of Posit Connect.
So right here is the command that we're going to use to deploy our dash application. I'm going to go ahead and copy it, bring it on over to VS Code again, running in Posit Workbench and just paste it. I'm not going to run it just yet, but let's run through this command because it reads pretty easily from left to right.
So we're using that RSConnect Python package. So this function right here to deploy a dash application to this server, this instance of Posit Connect. And then you can see this next argument, API key, and then there's some placeholder text right here. So this is where you're going to supply that API key to let Connect know that, hey, it's me deploying this dash application to that instance of Posit Connect.
Finding and using your API key
So where do we find this API key? Let's go back to Posit Connect, which I've already logged into. I'm going to close out this jumpstart example because we're pretty much done with it for the most part. And I'm going to go over here to my name in the top right corner. And you'll see API keys. So you can click on API keys. And you can see I've already created about four or so API keys. If you need to create a brand new one, you just select this box right here. Copy that API key. Come on back over to VS Code running in Posit Workbench and paste it right here.
Now API keys, you should always treat just like you would any password. So you want to make sure they're nice and safe. I've actually already added this to my environment. So I'm just going to delete this argument. And the RS Connect Python package will automatically detect it when it runs this command. And then the last little bit this dot and then the forward slash right here, it RS Connect will automatically detect this app.py application in the directory and deploy it. So that's it. This is the command. We'll hit enter and we'll let it run.
Deploying the application
So let's say I may have so let me just check the print working directory.
Let's try it one more time. I got delete the API key. There we go. And hit enter.
There we go. So it's going through a few checks right here, like validating the server, making sure that bundle looks good, everything seems to be in order. Okay, if anything's not in order, it should print some nice useful messages for you to help troubleshoot.
But what's actually happening right now, like when you deploy this application, what's going on. So for the most part, it's capturing my environment, it's looking to see what Python version Am I using? What libraries Am I using what versions of the libraries. So you can see like right here, for example, all these various Python libraries and their associated versions. It's making sure connect has those packages and the appropriate versions on the server and can replicate my environment is exactly as it's laid out here. Once it's established, it can and then deploys that dash application. So you can see deployment completed successfully.
So for the most part, it's capturing my environment, it's looking to see what Python version Am I using? What libraries Am I using what versions of the libraries. It's making sure connect has those packages and the appropriate versions on the server and can replicate my environment is exactly as it's laid out here.
And then it gives me two links right here, we'll select that top one, click on this. And it's going to bring us right to posit connect. And while this is running, kind of setting up right here, you'll notice as a publisher, I have this little gear icon in the top right corner. And these are some additional controls I have as a publisher of this dash application. But here it is, this is the dash application now hosted on posit connect.
