Beam supports hosting Streamlit apps. This example shows how to deploy a Streamlit app that analyzes the water consumption in New York City.

Streamlit App Structure

There are two components to deploying a Streamlit app on Beam:

  1. An streamlit_server.py file with your Beam code. You can view the source code here.
  2. A app.py file that hosts the Streamlit app

Here’s what the Beam-specific code looks like:

app.py
from beam import Image, Pod

streamlit_server = Pod(
    image=Image().add_python_packages(["streamlit", "pandas", "altair", "requests"]),
    ports=[8501],  # Default port for streamlit
    cpu=1,
    memory=1024,
    entrypoint=["streamlit", "run", "app.py"],
)

res = streamlit_server.create()

print("✨ Streamlit server hosted at:", res.url)

Deploying the Streamlit App

To deploy the app, run the following command:

python streamlit_server.py

This will deploy the Streamlit app and print the URL to the console:

$ python streamlit_server.py

=> Invocation details
curl -X POST 'https://a350a267-26cf-496a-a49c-df94395bdde6-8501.app.beam.cloud' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-d '{}'
✨ Streamlit server hosted at: https://a350a267-26cf-496a-a49c-df94395bdde6-8501.app.beam.cloud

You can paste the URL into your browser to use the app!