ProCodebaseProCodebase
  • ModusA Growth OS for your business, on WhatsAppKiosqSell more. Chase less.AI InterviewerAutomated screening & AI-led interviewsXperto AIAI prep companion for candidatesAI Tools HubResume builder, learning paths & more
  • Pre-Vetted DevelopersScreened, scored and ready to interviewAI-Native DevelopersSenior engineers on an hourly basis
  • Services
  • Features
  • AI Coaching
  • Jobs
  • FAQs
Sign inBook a demo
  • Services
  • Features
  • AI Coaching
  • Jobs
  • FAQs
Sign inBook a demo
ProCodebaseProCodebase

ProCodebase Technologies builds AI products for hiring and growth, and ships software for clients as a technical consultancy. We source, screen and deliver pre-vetted developers — so you only interview high-signal candidates.

Products

  • Modus
  • Kiosq
  • AI Interviewer
  • Xperto AI
  • AI Tools Hub

Hire & build

  • Pre-Vetted Developers
  • AI-Native Developers
  • Technical Consultancy
  • MVP Development
  • Features

Resources

  • Articles
  • Topics
  • Certifications
  • Collections
  • Jobs

Company

  • About Us
  • Contact Us
  • Book a Demo
  • FAQs

© 2026 ProCodebase Technologies. All rights reserved.

  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Deploying Streamlit Apps on the Web

author
Generated by
ProCodebase AI

15/11/2024

python

Sign in to read full article

Introduction

You've built an amazing Streamlit app locally, and now it's time to share it with the world. But how do you go from running your app on your computer to making it accessible online? In this guide, we'll explore different methods for deploying Streamlit apps on the web, from free and easy options to more advanced setups.

1. Streamlit Sharing: The Easiest Option

Streamlit offers a free hosting service called Streamlit Sharing, which is perfect for small projects and quick deployments.

How to use Streamlit Sharing:

  1. Push your Streamlit app to a public GitHub repository.
  2. Sign up for Streamlit Sharing at share.streamlit.io.
  3. Connect your GitHub account and select the repository containing your app.
  4. Choose the main file (usually app.py) and click "Deploy".

Your app will be live in minutes! It's that simple.

# Example app.py import streamlit as st st.title("My First Deployed Streamlit App") st.write("Hello, World!")

2. Heroku: Free Tier with More Control

Heroku is a popular platform-as-a-service (PaaS) that offers a free tier suitable for deploying Streamlit apps.

Steps to deploy on Heroku:

  1. Create a requirements.txt file listing your app's dependencies:
streamlit
pandas
numpy
  1. Create a Procfile (no extension) with the following content:
web: sh setup.sh && streamlit run app.py
  1. Create a setup.sh file:
mkdir -p ~/.streamlit/ echo "\ [server]\n\ headless = true\n\ port = $PORT\n\ enableCORS = false\n\ \n\ " > ~/.streamlit/config.toml
  1. Install the Heroku CLI and deploy:
heroku create your-app-name git push heroku main

Your app will be live at https://your-app-name.herokuapp.com.

3. AWS Elastic Beanstalk: Scalable and Robust

For more complex apps or those requiring additional services, AWS Elastic Beanstalk is a great option.

Deploying to AWS Elastic Beanstalk:

  1. Create a Dockerfile:
FROM python:3.8-slim WORKDIR /app COPY requirements.txt ./requirements.txt RUN pip3 install -r requirements.txt COPY . . EXPOSE 8501 ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
  1. Create an Elastic Beanstalk application and environment using the AWS Management Console.

  2. Deploy your app using the AWS CLI:

eb init -p docker your-app-name eb create your-environment-name eb deploy

4. Google Cloud Run: Serverless and Cost-Effective

Google Cloud Run is a serverless platform that's great for Streamlit apps with varying traffic.

Deploying to Google Cloud Run:

  1. Build your Docker image:
docker build -t gcr.io/your-project-id/streamlit-app:v1 .
  1. Push the image to Google Container Registry:
docker push gcr.io/your-project-id/streamlit-app:v1
  1. Deploy to Cloud Run:
gcloud run deploy --image gcr.io/your-project-id/streamlit-app:v1 --platform managed

Best Practices for Deploying Streamlit Apps

  1. Use environment variables: Store sensitive information like API keys in environment variables instead of hard-coding them in your app.
import os import streamlit as st api_key = os.environ.get("API_KEY") st.write(f"Using API key: {api_key}")
  1. Optimize for performance: Minimize the use of st.cache for frequently changing data, and consider using async operations for I/O-bound tasks.

  2. Handle errors gracefully: Use try-except blocks to catch and display errors in a user-friendly manner.

try: result = potentially_error_prone_function() st.success("Operation completed successfully!") except Exception as e: st.error(f"An error occurred: {str(e)}")
  1. Version your dependencies: Use a requirements.txt file with specific versions to ensure consistency across different environments.

  2. Test thoroughly: Before deploying, test your app with different inputs and edge cases to ensure it behaves as expected.

By following these deployment methods and best practices, you'll be well on your way to sharing your Streamlit apps with the world. Each deployment option has its pros and cons, so choose the one that best fits your project's needs and your technical expertise. Happy deploying!

Popular tags

pythonstreamlitweb deployment

Share now!

Like & bookmark

Related collections

  • Mastering Scikit-learn from Basics to Advanced

    15/11/2024 · Python

  • Mastering Hugging Face Transformers

    14/11/2024 · Python

  • LlamaIndex: Data Framework for LLM Apps

    05/11/2024 · Python

  • Automate Everything with Python: A Complete Guide

    08/12/2024 · Python

  • Mastering Pandas: From Foundations to Advanced Data Engineering

    25/09/2024 · Python

Related articles

  • Understanding Transformer Architecture

    14/11/2024 · Python

  • Mastering Chains

    26/10/2024 · Python

  • Demystifying Tokenization in Hugging Face

    14/11/2024 · Python

  • Advanced Features and Best Practices for Streamlit

    15/11/2024 · Python

  • Mastering Feature Scaling and Transformation in Python with Scikit-learn

    15/11/2024 · Python

  • Leveraging Python for Efficient Structured Data Processing with LlamaIndex

    05/11/2024 · Python

  • Mastering NumPy Fourier Transforms

    25/09/2024 · Python

Popular category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design