Deploy Shiny App
Let’s get our application up on the internet. We’ll be using Connect Cloud.
Connect Cloud provides a cloud environment to quickly publish, share, and showcase your work – it’s free for public GitHub repositories!
If you want to deploy your application (for free!), you will need a GitHub account before continuing.
Here’s the app we created in the Shiny Express Lab.
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [editor, viewer]
#| layout: horizontal
#| viewerHeight: 500
from palmerpenguins import load_penguins
from plotnine import aes, geom_histogram, ggplot, theme_minimal
from shiny.express import input, render, ui
dat = load_penguins()
species = dat["species"].unique().tolist()
ui.input_radio_buttons("species", "Species", species, inline=True)
@render.plot
def plot():
sel = dat[dat["species"] == input.species()]
return (
ggplot(aes(x="bill_length_mm"))
+ geom_histogram(dat, fill="#C2C2C4", binwidth=1)
+ geom_histogram(sel, fill="#447099", binwidth=1)
+ theme_minimal()
)
Step 0: GitHub account
Before starting make sure you have your github account ready. You will be creating a repository submitting code into the repo.
You can do this lab completely within the GitHub web interface by copying code into a new file.
Step 1: Application requirements.txt
When we deploy our application, we need to make sure the packages we use are installed. Save the below into a requirements.txt
file.
shiny
palmerpenguins
plotnine
and then install them with
pip install -r requirements.txt
You will need to have the requirements.txt
file in the repository so Connect Cloud can create the Python environment.
Step 2: The application code
Copy the code from our application into a file called app.py
app.py
from palmerpenguins import load_penguins
from plotnine import aes, geom_histogram, ggplot, theme_minimal
from shiny.express import input, render, ui
= load_penguins()
dat = dat["species"].unique().tolist()
species
"species", "Species", species, inline=True)
ui.input_radio_buttons(
@render.plot
def plot():
= dat[dat["species"] == input.species()]
sel return (
="bill_length_mm"))
ggplot(aes(x+ geom_histogram(dat, fill="#C2C2C4", binwidth=1)
+ geom_histogram(sel, fill="#447099", binwidth=1)
+ theme_minimal()
)
Step 3: Deploy to Connect Cloud
We’ll be deploying our shiny application to Connect Cloud. Here are the steps to publish your application.
- Click the Publish icon button on the top of your Portfolio page
- Select Shiny
- Select the public repository that you created in this tutorial
- Confirm the branch
- Select
app.py
as the primary file - Click Publish
Publishing will display status updates during the deployment process. You will also find build logs streaming on the lower part of the screen.
Congratulations! You successfully deployed to Connect Cloud and are now able to share the link with others.
Step 4: Republish application
If you update the code to your application or the underlying data source, commit and push the changes to your GitHub repository.
Once the repository has the updated code, you can republish the application on Connect Cloud by going to your Content List and clicking the republish icon.