Deployment using Heroku

Learn how to deploy your Streamlit app using Heroku.

In this tutorial, we’ll deploy a Streamlit app using Heroku.

You will need to create some accounts on Heroku and Github:

We’ll deploy the “githubProfileScraper” app (Click here to go to the app page on GitHub). We’ve already built our own GitHub profile scraping app in the “Build a Streamlit App to Scrape Github Profiles” chapter.

Upload the necessary files

We need the following files to be uploaded in the GitHub repository:

The requirements.txt file

Write the following command to list all the required libraries.

pip freeze > requirements.txt

The above command lists down all the libraries your app uses in a text file. Ensure that your virtual environment is activated before you type the above command.

The Procfile file

Create a file and name it Procfile. Make sure it has no extension and its name is set to Procfile. Write the following commands in this file:

web: sh setup.sh && streamlit run app.py

Note: If your app.py file is inside a folder named app, it should be streamlit run app/app.py.

The setup.sh file

Create a file and name it setup.sh. Write the following commands:

mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"{your_email_id}\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\port = $PORT\n\
" > ~/.streamlit/config.toml

Note: Make sure you replace your email ID.

Once you’ve created all the files, upload your app along with all the files to GitHub. Your files should look similar to as shown below.

Ask