For more information on concepts covered in this lesson, you can check out:
Deploying Your Dash Application to Heroku
00:13 Dash apps are Flask apps, so both share the same hosted deployment options. In this section, you’ll deploy your app on Heroku. Before you get started, make sure you’ve installed the Heroku Command-Line Interface and Git.
The output you see may change slightly depending on your operating system and the version you have installed, but you shouldn’t get an error. With those two requirements present, let’s make a start on the deployment. Firstly, there’s a small change you need to make on
app.py. After you initialize the app, add a new variable called
Next, in the project’s root directory, create a file called
runtime.txt, where you’ll specify a Python version for your Heroku app. When you deploy your app, Heroku will automatically detect that it’s a Python application and will use the correct
buildpack. If you also provide a
runtime.txt, then it’ll pin down the Python version that your app will use.
You may have noticed there’s a package in
requirements.txt you haven’t seen until now: Gunicorn. “Green unicorn” is a WSGI HTTP server that is frequently used for deploying Flask apps to production.
02:39 This file tells the Heroku app what commands should be executed to start your app. In this case, it starts a Gunicorn server for your dashboard. Next, you’ll need to initialize a Git repository. To do that, go to your project’s root directory and execute the following command.
This will start a Git repository in
avocado_analytics/. It’ll start tracking all of the changes you make to the files in that directory. However, there are files you don’t want to track using Git. For example, you usually want to remove Python compiled files, the contents of your virtual environment folder, or metadata files such as
To avoid tracking unnecessary files, create a file called
.gitignore in the root directory. Then, enter the following content into it. This will make sure your repository doesn’t track unnecessary files.
03:57 Before the final step, make sure you have everything in place. Your project structure should look like this. Finally, you need to create an app in Heroku, push your code there using Git, and start the app using one of Heroku’s free server options.
04:17 To do this, you’ll need to create an account on heroku.com. Once you’ve done that, you’ll need to choose a unique name for your project. If you try to use a name that’s already in use, such as the one you’ll see me using onscreen, then you’ll get an error.
And that’s it! You’ve built and deployed your dashboard. Now you just need to access it to share it with your friends. To access your app, use the
APP-NAME and visit
<APP-NAME>.herokuapp.com in your browser, as seen onscreen.
Become a Member to join the conversation.