Streamlit#
Deploy a Streamlit app on Ploomber in seconds with this guide.
First, create an account.
To deploy a Streamlit app you need at least two files:
Your application file (
app.py
)A dependencies file (
requirements.txt
)
Application file#
Your app.py
must be a Streamlit application. An example is available here.
Dependencies#
To deploy a new project, list your dependencies in a (requirements.txt
). You must include the streamlit package. If you’re using pandas and numpy together, your requirements.txt
file will look like this:
# sample requirements.txt
streamlit
pandas
numpy
Testing locally#
To test your Streamlit app, create a virtual environment and install the packages:
pip install -r requirements.txt
Then run the following command to start the application:
streamlit run app.py
Deploy#
Deploy from the menu
Once you have all your files, create a zip file.
To deploy a Streamlit app from the deployment menu, follow these instructions:
Try an example
To download and deploy an example Streamlit application start by installing Ploomber Cloud and setting your API key:
pip install ploomber-cloud
ploomber-cloud key YOUR-KEY
Tip
If you don’t have an API key yet, follow the instructions here.
Now, download an example. It will prompt you for a location to download the app. To download in the current directory, just press enter.
ploomber-cloud examples streamlit/data-viz
Note
A full list of Streamlit example apps is available here.
You should see a confirmation with instructions on deploying your app. Now, navigate to your application:
cd location-you-entered/data-viz
Deploy from the CLI
Initialize and deploy your app with:
ploomber-cloud init
ploomber-cloud deploy --watch
Tip
To ensure your app doesn’t break on re-deployments, pin your dependencies.
Production deployments#
Ploomber has features to help you deploy production-ready Streamlit apps
Authentication#
Our integration with Auth0 allows you to easily add authentication to any Streamlit app. There’s no need to modify your Streamlit app code, only pass your Auth0 configuration parameters. Check out the sample app.
Connecting to a DB#
You can use the st.connection API for connecting to a database from a Streamlit app. Check out this sample app that demonstrates DB connection.
You can set the SQLAlchemy URI of your DB as an environment variable DB_URI
and pass it using the url
argument:
import streamlit as st
from os import environ
conn = st.connection(name="db_connection",
type='sql',
url=environ["DB_URI"])
You can pass any relevant value as the name
argument. When deploying on Ploomber Cloud the DB_URI
value needs to be set as a secret:
Note that the database URI is a SQLAlchemy URI and should have the format:
dialect://username:password@host:port/database
Here’s an example of a Postgres
connection URI:
postgresql://scott:tiger@localhost:5432/mydatabase
To learn more about the URI format refer to the documentation.
Other features#
Ploomber Cloud supports many features to help you build Streamlit applications quickly!
Integration with GitHub
Safely store secrets such as API keys
Usage analytics such as unique visitors, total requests, etc.
Spin up larger resources (CPUs and RAM)
Spin up GPUs
Add custom domains or subdomains to your application
Task queues to scale applications to more users
Troubleshooting#
By default applications run with Python 3.11. Refer to this section for customized deployments.
Here is a sample Docker-based Streamlit
application.