Skip the guide and deploy the sample app
Deploy a Streamlit app to Connect Cloud
In this guide, you deploy a Streamlit app to Connect Cloud and get a URL you can share. You can deploy from GitHub, from Positron or VS Code, or from the command line. The sample app charts the share of income held by the richest 5% of the population in each country.

The source code is available in the examples-streamlit repository.
Getting started
Whichever method you choose, you need the following:
A Connect Cloud account.
A Streamlit app. This guide uses the sample app, which has a main file (Connect Cloud calls it the primary file) named
app.pyand adata.csvdata file.A
requirements.txtfile that lists the Python packages you use, in the same folder asapp.py. The sample app needs the following packages:requirements.txt
streamlit pandas altair
Save this file as app.py.
app.py
import os.path
import altair as alt
import pandas as pd
import streamlit as st
HERE = os.path.dirname(os.path.abspath(__file__))
st.title("Top 5%" " income share")
st.markdown("Share of income received by the richest 5%" " of the population.")
DATA = os.path.join(HERE, "data.csv")
@st.cache_data
def load_data(nrows):
return pd.read_csv("./data.csv", nrows=nrows)
data_load_state = st.text("Loading data...")
data = load_data(10000)
data_load_state.text("")
countries = st.multiselect(
"Countries",
list(sorted({d for d in data["Entity"]})),
default=["Australia", "China", "Germany", "Japan", "United States"],
)
earliest_year = data["Year"].min()
latest_year = data["Year"].max()
min_year, max_year = st.slider(
"Year Range",
min_value=int(earliest_year),
max_value=int(latest_year),
value=[int(earliest_year), int(latest_year)],
)
filtered_data = data[data["Entity"].isin(countries)]
filtered_data = filtered_data[filtered_data["Year"] >= min_year]
filtered_data = filtered_data[filtered_data["Year"] <= max_year]
chart = (
alt.Chart(filtered_data)
.mark_line()
.encode(
x=alt.X("Year", axis=alt.Axis(format="d")),
y=alt.Y("Percent", axis=alt.Axis(format="~s")),
color="Entity",
strokeDash="Entity",
)
)
st.altair_chart(chart, use_container_width=True)
if st.checkbox("Show raw data"):
st.subheader("Raw data")
st.write(filtered_data)
st.markdown("Source: <https://ourworldindata.org/grapher/top-5-income-share>")Get data.csv from the sample repository.
To preview the app before you deploy, install the dependencies and run it from the folder that contains app.py:
Terminal
pip install -r requirements.txt
streamlit run app.pyChoose a deployment method
| Method | When to use it | Jump to |
|---|---|---|
| GitHub | Your code is on GitHub and you want it to update when you push (public repositories only on free accounts) | Deploy from GitHub |
| Posit Publisher | You work in Positron or VS Code and do not use GitHub | Deploy from Positron or VS Code |
| rsconnect-python | You want to deploy from a terminal or automate deployments | Deploy from the command line |
For more on how these methods differ, see Publishing.
Deploy from GitHub
Use this method when your app’s code is in a GitHub repository and you want changes you push to publish automatically. On a free account, your repository must be public, so anyone can see your code.
- Commit
app.pyandrequirements.txt, then push your app to a GitHub repository. - Sign in to Connect Cloud.
- Click Publish at the top of your Home page. If this is your first time publishing, Connect Cloud prompts you to install the GitHub App, which lets Connect Cloud read your repository.
- Select Streamlit.
- Select your repository.
- Check that Branch is the branch that has your content, usually
main. - Select
app.pyas the Primary file. - Leave Automatically publish on push on if you want Connect Cloud to update what you published each time you push to this branch. Turn it off to update only when you choose.
- Click Publish.
- Result: Connect Cloud shows a log of the install steps while it deploys. When it finishes, your app is live at an address like
https://[content-id].share.connect.posit.cloud, where[content-id]is a unique identifier that Connect Cloud picks. You can set a custom name to change the URL. - Update or redeploy: Commit and push to the connected branch and Connect Cloud republishes automatically. If you turned off automatic publishing, click Republish on the content’s card on your Home page. See Republishing.
For all options, see Publish from GitHub.
Deploy from Positron or VS Code
Use this method when you work in Positron or VS Code and want to publish your app directly. Positron includes the Posit Publisher extension. In VS Code, install it from the marketplace first.
- Open your project folder in Positron, or in VS Code with Posit Publisher installed.
- Click the Posit Publisher icon in the Activity Bar.
- Next to CREDENTIALS, click + and select Posit Connect Cloud. A credential is a saved connection to your Connect Cloud account. Your browser opens.
- In your browser, check that the Authorize Access code matches the code in Positron or VS Code. Then click Continue and Authorize.
- Return to Positron or VS Code and accept or change the name for this credential. Do this once.
- Click the + next to Deployments. If Posit Publisher asks which file to publish, select
app.py. - Enter a title for your content, then select the credential you just added.
- Under PROJECT FILES, check that the list includes
app.py,data.csv, andrequirements.txt. Connect Cloud uploads only the files in this list. - Click Deploy Your Project.
- Result: A success message appears in the lower right of Positron or VS Code. Click View Content in the extension to open the app on Connect Cloud. Its address has the form
https://[content-id].share.connect.posit.cloud, where[content-id]is unique to your app. - Update or redeploy: Save your changes, open Posit Publisher, select the previous deployment, and click Deploy Your Project again. Keep the
.positfolder in your project. It remembers which Connect Cloud content this project publishes to, so the next deploy updates the same content instead of creating a new one.
For the configuration file, multiple deployments per project, and troubleshooting, see Publish from your IDE.
Deploy from the command line
Use this method to deploy from a terminal or to automate deployments, for example, from a script. It requires rsconnect-python version 1.31.0 or higher.
Install the
rsconnect-pythoncommand-line tool.Terminal
pip install rsconnect-pythonAdd your Connect Cloud account. Replace
<YOUR_ACCOUNT_HERE>with your account name from your account page. Your browser opens for you to authorize access.Terminal
rsconnect add --connect-cloud \ --account "<YOUR_ACCOUNT_HERE>" \ --name cloudDeploy the folder that contains
app.pyandrequirements.txt.Terminal
rsconnect deploy streamlit . --name cloud
- Result: The command prints the URL of your content. Open the URL to see the content’s page on Connect Cloud. Add
--quietto print only the URL. - Update or redeploy: Run the same
rsconnect deploycommand again. The directory remembers where you deployed, so you can omit--name.
For noninteractive credentials, examples for automated builds, and other options, see Publish from your console or terminal.
After you deploy
Common things to set up next. They work the same however you deployed your app:
- Passwords and API keys: Store them as secret variables, not in your code. Add them under Variables in content settings, or during publishing. Read them with
os.getenv("NAME"). - Access and sharing: Control who can view your app in Sharing.
- Scheduling: On paid plans, schedule your app to republish at set times, for example, to refresh data each day.
- Custom name and domain: Change the app’s URL with a custom name or a custom domain.
- Upload size limit: The upload size limit applies when you upload your project files from your editor or the command line.
Troubleshooting
- Missing package error: Add the package to
requirements.txtand republish. Make sure the file is in the same directory asapp.py. - Missing data file: Commit the file to the repository, or include it under PROJECT FILES in Posit Publisher. Connect Cloud can use only the files you deploy with the app.
st.secretserror: Connect Cloud does not supportst.secrets. Store the value as a variable and read it withos.getenv.- Repository not listed: Confirm that the GitHub App has access to it.
- The deploy command stops before uploading: The folder you are deploying needs a
requirements.txtfile. See Create a requirements.txt file.
If your deployment still fails, read the log that Connect Cloud shows while it deploys and look for the first error. You can also try Error Assist, which gives guidance based on your log output.