How to Deploy Streamlit APP to Heroku?

Yanwei Liu
2 min readSep 28, 2020

--

Streamlit’s open-source app framework is the easiest way for data scientists and machine learning engineers to create beautiful, performant apps in only a few hours! All in pure Python. All for free.

But, if you want to deploy it online, how can we achieve it?

Just follow the steps below to get your first Streamlit APP online.

Notice: you should create your own Heroku account and install git in advance.

Step1. Prerequisite

Suppose that you have finished your awesome Streamlit APP, you still need to create 4 files in your project folder.

(runtime.txt, setup.sh, Procfile, requirements.txt)

runtime.txt 
# To let heroku to know which programming language should use
python-3.7.6
setup.sh
# To do some automation task so that stremlit can work correctly on heroku
# please replace your@email.com with your own email
mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"your@email.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
Procfile
# let heroku know which command to execute to run streamlit app
web: sh setup.sh && streamlit run app.py
requirements.txt
# add the python package you will use inside your project
# for me, it would be:
matplotlib==3.2.1
numpy==1.18.4
tensorflow==1.15.2
Keras==2.0.0
Pillow==7.1.2
streamlit-folium
streamlit

Step2. Work with Heroku CLI and git

We have to set up Heroku environment before pushing our app to the cloud, please make sure that you have installed the Heroku CLI correctly

$ cd path/to/streamlit_project
$ heroku login
$ git init
$ heroku create
$ git add .
$ git commit -m "Enter your message here"
$ git push heroku master
$ heroku ps:scale web=1
$ heroku open

Reference

--

--

No responses yet