emunozlorenzo / Deploying-Streamlit-with-Heroku

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deploying a Streamlit Dashboard with Heroku

alt text Eduardo Muñoz

User Interface

Playgrounds

  1. Create a Git Repo

Note: Heroku allows deployment using Git or Docker.

git init
  1. Build your App
import streamlit as st
import pandas as pd
import numpy as np

def main():
# Your Code
if __name__ == "__main__":
    main()
  1. Test your App (Local Environment)
~$ streamlit run app.py
  1. Create your requeriments.txt file

This file contains the libraries that your code needs to work. To do this, you can use pipreqs.

pipreqs /path/to/your/app/

After this command, a requirements.txt will be created in the folder of your app

matplotlib==3.1.0
streamlit==0.56.0
pandas==1.0.2
seaborn==0.9.0
numpy==1.16.3
  1. Setup.sh and Procfile

Heroku needs these files for starting the app

- setup.sh : create a streamlit folder with both credentials.toml and config.toml files.
- Procfile : This file executes the setup.sh and then call streamlit run to run the app
# Setup.sh
mkdir -p ~/.streamlit/

echo "\
[general]\n\
email = \"your-email@domain.com\"\n\
" > ~/.streamlit/credentials.toml

echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
# Procfile
web: sh setup.sh && streamlit run app.py
  1. Create a Heroku Account

Create a free account

  1. Install Heroku CLI

Follow these steps

  1. Login into Heroku CLI

Move to your App folder and execute heroku login

  1. Deploy the App

Deploy your app by running heroku create in your app folder

  1. Check it

Check your app by running heroku ps:scale web=1

After that, push your code

git add .
git commit -m "message"
git push heroku master
  1. Open it

Open your app using heroku open

Thanks to Gilbert Tanner for his tutorial

About


Languages

Language:HTML 60.9%Language:Python 38.7%Language:Shell 0.4%