DEV Community

Cover image for How to deploy streamlit app to Heroku
Kevork Keheian
Kevork Keheian

Posted on

How to deploy streamlit app to Heroku

Hello everyone,
This is a step by step tutorial about how to deploy your Streamlit app to Heroku.

What is streamlit?

Streamlit is an open-source python framework for Machine Learning and Data Science teams and individuals.
See it yourself: https://streamlit.io
You can deploy your app using streamlit sharing, but the problem is that you only have 3 apps with the free version.

So what you will see now is how you can deploy your app to Heroku

Requirements:

  • python installled
  • streamlit installed (You can install streamlit using pip install streamlit)
  • GitHub account

Once the above are installed

You can check their documentation about creating you app.

And now it's time to deploy 🎇

You need to add 2 additional files to your project.
1- You need to add a setup.sh file which is used to add shell commands inside the file.

mkdir -p ~/.streamlit/
echo "\
[server]\n\
headless = true\n\
port = $PORT\n\
enableCORS = false\n\
\n\
" > ~/.streamlit/config.toml
Enter fullscreen mode Exit fullscreen mode

Then add a new file called Procfile and inside it paste the following code:

web: sh setup.sh && streamlit run app.py
Enter fullscreen mode Exit fullscreen mode

And finally a requirements.txt file

streamlit
matplotlib
numpy
pandas
Enter fullscreen mode Exit fullscreen mode

and the other packages that you are using in your app.

Now head over to GitHub and create a new repository and publish your code to github. You can check this article to see how you can do that.

Once the code is on GitHub head over to Heroku and create a new app:
Create a new app on Heroku

Choose a name to your app and click "Create app"

Heroku - create a new app

You can leave the pipeline empty for the time being and choose "GitHub" as your deployment method.
And in the Connect to GitHub section choose your username/org, type the name of the repository and click search. After you click search you can see the repo, click on the Connect button next to the repo.
Heroku - choose deployment method

Once you click connect you can see at the end of the page The Manual deploy section. Just click Deploy Branch and watch the magic happen.

Once the deployment is finished you can check your app app-name.heroku.com.
In this case we chose streamlit-heroku-app as our app name so if you need to navigate to streamlit-heroku-app.heroku.com to see the deployed streamlit app.

Heroku - manaul deployment

Note: the app is no longer available on heroku

Top comments (0)