Deploying Dash Apps to Heroku
By Angela C
September 30, 2021
Reading time: 2 minutes.
A Dash app is a Flask app so the same deployment options apply.
The recommended method for securely deploying Dash applications is using Dash Enterprise.
Dash Enterprise is Plotly’s commercial product for developing & deploying Dash Apps on your company’s on-premises Linux servers or VPC (AWS, Google Cloud, or Azure).
I have deployed to Linode and Python Anywhere before but now I am going to deploy to Heroku. You can have up to 5 apps deployed for free on Heroku.
Heroku is recommended by Dash for sharing public Dash apps for free.
The instructions for deploying a Dash app to Heroku are outlined on https://dash.plotly.com/deployment. If followed precisely you can get an app up and running quite quickly! My simple weather app is here at https://angela1c-weather-app.herokuapp.com. This app is very much a work in progress though…
For this you need Git, Python, the Heroku command line interface and Gunicorn to be installed.
- Create a new folder for the project
- Initialise the folder with ‘git’
- Create a virtual environment in the folder and activate it.
- Install the app’s dependencies within the virtual environment.
pip install gunicorn. Gunicorn is a WSGI HTTP server that is used for deploying Flask apps into production.
- Create a Python application and name it
app.py file should include:
app = dash.Dash(__name__) server = app.server
Add the following files that are needed for deployment:
requirements.txtfile containing a list of Python dependencies for the application
web: gunicorn app:server. This says to start a gunicorn server for the app.
Procfilerefers to the filename
serverrefers to the variable
.gitignorelist of files that should not be tracked by Git.
Install the Heroku command line interface.
heroku --versionto check if it is already installed
When you have the app up and running on the local host in the virtual environment, add the app’s dependencies to the
You can pipe the output of
pip freeze to the
requirements.txt file with the following command:
pip freeze > requirements.txt.
- Initialise Heroku, add files to Git and deploy
heroku create <my-app-name># set your app name here.
git add .to add all files to git
git commit -m"a descriptive git message"
git push heroku masterto deploy the app to Heroku Once that is complete set
heroku ps:scale web=1to run the heroku app with one Heroku ‘dyno’.
I have deployed an app to Heroku here. It is very much a work in progress but updating it is as easy to deploying it. It is similar to push changes to GitHub.
10 Modify an app locally and update deployed app.
git statusto view any changes made since the last time it was pushed.
git add .to add all files.
git commit -m"short message describing the changes"
git push heroku masterto push the changes to Heroku.