I recently started building dashboard for my python programs using the Dash framework by Plotly. Here are the steps I took to deploy a simple dashboard on AWS Elastic Beanstalk. Full credit to previous authors whose excellent work led me to this point:
- Deploying Dash to Elastic Beanstalk by Jamie Phillips (I diverge from Jamie in as much as he uses the AWS Elastic Beanstalk GUI management console but I’m using the command line interface (CLI), but otherwise my post is highly indebted to his. Thanks, Jamie!).
- Interactive Python Dashboards with Plotly and Dash by Jose Marcial Portilla (I can’t recommend this course highly enough; it’s the best resource out there for learning Dash. Jose deploys his apps in Heroku, not AWS, but the basics are very similar. Be sure to check out all of Jose’s python courses on Udemy!).
- Beginner’s guide to deploying a Flask App by Milo Spencer-Harper (great guide to getting started with AWS EB CLI, and Dash is built on Flask so there’s a lot of similarities).
- Useful review about preconfigured docker containers.
Here are the steps to take when deploying your Dash app using elastic beanstalk:
In terminal, make a new directory for your app:
mkdir chucknorris && cd $_
Create and save an empty readme file using the text editor of your choice:
atom readme.md (this step isn’t absolutely necessary, but it’s always a good idea to include a readme file so that other git users or future-you know what this was all about)
Initiate a git repository:
Add that file to your repo:
git add .
Make your first commit:
git commit -m "chuck norris never commits to anything."
Set up a virtual environment (if you haven’t installed or don’t know what this is, please refer to Jamie’s blog post above):
Activate that environment:
Install the necessary packages you’ll need for this example:
pip install dash
pip install dash-renderer
pip install dash-html-components
pip install dash-core-components
Freeze your requirements:
pip freeze > requirements.txt
Create a python program called
application.py that contains the following code:
try running that file:
python application.py and you’ll see this:
So your app is running! You can navigate to it in your local browser if you wish. Shut it down with
ctrl + c
Deactivate your virtual environment.
Install Amazon Web Services Elastic Beanstalk (I assume you already have an AWS account; if not, please refer to the post by Milo Spencer-Harper as mentioned above).
pip install awsebcli
Initialize elastic beanstalk:
eb init and choose all the default settings in the dialogue prompts that follow. When it asks if you want to use CodeCommit or SSH for your instances, select “no”.
This will create a hidden folder with your elastic beanstalk settings. Now the contents of your folder should look like this:
Add and commit everything to git:
git commit -m "superman wears chuck norris pajamas"
Next we create an instance of our app on AWS:
In the dialogue prompts that follow, go ahead and choose the defaults. Now get up and make a sandwich, because this is going to take a while. When you come back, you should have a message that says your app has launched successfully. Somewhere above that, you’ll also see a line with “CNAME” that has the URL of your new app:
Select the CNAME and paste it into your browser:
Congratulations, you’ve just deployed your first Dash app on AWS! Just as a reminder, every time you make a change you’ll want to make a new commit and then
eb deploy to update the live app. Best of luck! Chuck Norris would be proud.