Plotly Dash and the Elastic Beanstalk Command Line

Austin Lasseter

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:

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: git init

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): virtualenv cordellwalker

Activate that environment: source cordellwalker/bin/activate

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. deactivate

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 add.
git commit -m "superman wears chuck norris pajamas"

Next we create an instance of our app on AWS: eb create

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.

Austin Lasseter

Written by

https://austinlasseter.github.io

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade