This tutorial explains how to deploy a Streamlit data app to the cloud with user authentication using Morph. With this method, there’s no need for Docker builds typically required when deploying Streamlit apps to Cloud Run. This makes sharing apps within your team simpler and quicker.
Morph is a cloud service designed to automatically deploy internal data and AI apps from your GitHub repository to the cloud, providing built-in user authentication for easy sharing.
Now that Morph supports Streamlit deployment, this tutorial will guide you through deploying a Streamlit application. Make sure you’ve logged in to morph-data.io beforehand.
TL;DR
The sample code from this tutorial is available in the repository below:
GitHub - shibatanaoto/streamlit-morph-sample
Fork the above repository and follow the video tutorial linked below to deploy your Streamlit app to the cloud and share it with invited members:
Preparation
Install the necessary packages before starting:
pip install streamlit pandas
Building a Simple Streamlit App
As this tutorial focuses mainly on deployment, we’ll use a simple Streamlit app. First, create a file named main.py. (Do not change this filename.)
import streamlit as st
import pandas as pd
import numpy as np
st.markdown("# Hello world!!!")
df: pd.DataFrame = pd.DataFrame(
np.random.randn(30, 3),
columns=["x", "y", "z"]
)
st.line_chart(df)
Run the app locally to check it.
streamlit run main.py
Configuring Morph Deployment
Next, create a file named morph_project.yml
in the same directory as main.py. Enter the following configuration, adjusting the runtime version according to your Python environment (supported versions are Python 3.9 to 3.12):
version: '1'
build:
framework: streamlit
runtime: python3.12
deployment:
provider: gcp
Detailed documentation for morph_project.yml, including how to adjust CPU and memory based on your needs, can be found here:
After configuration, generate a requirements.txt file with your dependencies and push the changes to GitHub:
pip freeze > requirements.txt
Deploying to Morph
Log in to https://morph-data.io, click the “+Create” button on the homepage, connect your GitHub repository, and select the repository and branch. Deployment starts automatically.
On the homepage, you’ll see a list of your created apps. Select the app with the same name as your repository. Under the “Deployments” tab, you can view the build status. Once it shows “Ready,” the deployment is complete.
Click the “Open” button to view the deployed app. There might be a slight cold start delay initially, but you should see your application successfully loaded.
The deployed app has built-in user authentication, meaning only members invited via the “Member Access” dashboard can access it.
To invite members, use the following screen. You can invite 5 members in Free plan.
Morph simplifies deploying Streamlit apps to the cloud and securely sharing them with your team.
Morph is also expanding support for full-stack frameworks like Next.js and HonoX. If you have requests for additional frameworks, feel free to reach out 🚀
Top comments (0)