DEV Community

Naoto Shibata for Morph

Posted on • Originally published at Medium on

3 1 1

Tutorial: Deploying a User-Authenticated Streamlit App in Just 5 Minutes.

header-image

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Run the app locally to check it.

streamlit run main.py
Enter fullscreen mode Exit fullscreen mode

app-run

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
Enter fullscreen mode Exit fullscreen mode

Detailed documentation for morph_project.yml, including how to adjust CPU and memory based on your needs, can be found here:

morph_project.yml - Docs

After configuration, generate a requirements.txt file with your dependencies and push the changes to GitHub:

pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

repository

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.

create-app

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.

deployment-status

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.

deployed-app

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.

user-invitation

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)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay