How to deploy your Streamlit app to Heroku. Here are the 4 main steps:
- Prepare your app files
- Create a Git repository
- Create a Heroku app
- Deploy your app on Heroku
- Rename your Streamlit app to
app.py
- All your data files should be in the same folder as
app.py
. In my case I only have 1 datafile, namely:unemployment.tsv
- Create a file called
requirements.txt
and include the name of all the packages used in your app. In my case I only used:
pandas
streamlit
altair
vega_datasets
matplotlib
numpy
plotly
seaborn
- Copy the
setup.sh
andProcfile
from this repository in your folder - Create a file named
README.md
and add instructions for users to run your app using Streamlit if they choose to clone this repository. Here is an example of what you can write inREADME.md
:
# README #
After cloning this repository you can run the Streamlit app using the following command: `streamlit run app.py`
- On GitHub or BitBucket create an empty repository. Note that you need to have an account on these platforms. In my case, I used BitBucket and created an empty repository called
streamlit
, https://bitbucket.org/abheda/streamlit.git - Commit and push your files into your repository. In my case I executed the following commands in my folder (note that the git url will be different for you and the name of the datafiles as well):
git init
git remote add origin https://bitbucket.org/abheda/streamlit.git
git add README.md
git add setup.sh
git add Procfile
git add requirements.txt
git add app.py
git add unemployment.tsv
git commit -m "first commit"
git push origin master
- Create a free account on Heroku
- Install the Heroku CLI. In my case, I had challenges installing the CLI using the installer provided for Windows. Instead, I have used the
npm
approach. In this case you need to havenode
andnpm
installed. Namely, I executed the following command:
npm install -g heroku
- Create a new app on Heroku using the following commands. In my case, I called the app
uncc-va-project
heroku login
heroku create uncc-va-project
- Once the create command executes it will return 2 URLs. One URL that you can use to access your app online and a Git URL that we will use to deploy your app. In my case, I got the following response:
Creating app... done, ⬢ uncc-test-streamlit
https://uncc-va-project.herokuapp.com/ | https://bitbucket.org/abheda/streamlit.git
- At this point this is an empty app - you can access the URLs but there is nothing interestng there
- To deploy your app on Heroku you need to push your files in the Heroku git repository, which was returned at the time of app creation. In my case this is
https://git.heroku.com/uncc-va-project.git
and I have executed the following commands:
git remote add heroku https://git.heroku.com/uncc-va-project.git
git push heroku master
- It will take some time for the app to be deployed. If successful you will get a message like this:
remote: -----> Launching...
remote: Released v3
remote: https://uncc-va-project.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
- At this point you can access your app using the provided URL. In my case: https://uncc-va-project.herokuapp.com/