Hosting Your Interactive Visualizations
By: Sam Bell
Tags: Data Visualization, Bokeh, Data Science, Python, Heroku

Bokeh & Heroku

Click the link below to see for yourself!

https://voterturnoutmap.herokuapp.com/MapScript

Visualizations make data accessible to everyone. They turn mind-numbing excel spreadsheets into fun and easy to understand graphs. They summarize, highlight, and good visualizations also allow the user to explore the data themselves. The user can explore the data to answer their own questions and make their own discoveries.

“Look at this graph.”

As Python programmers, many are familiar with Matplotlib and Plotly, but lately I’ve been experimenting with Bokeh. There are some great tutorials on using Bokeh that I would encourage you to visit —

These tutorials demonstrate how to create interactive visualizations, but the interaction is only displayed through gif or video. You can have the visualizations you create hosted locally on your own server, but isn’t there a way to host the interactive visualizations so readers could interact? Yes, and the answer is Heroku!

Heroku has great documentation and step-by-step directions catered to different programming languages. I am going to guide you through what I did to turn my visualization into an application. This is very useful if you ever want to make your creations easily shareable.

Setup

First, you have to create an account with Heroku, and since we are data scientists, I am going to assume you are working with Python. Make sure your Python is up to date! You are also going to need a GitHub account. Do it! Finally, you will need to install Heroku. It’s easy enough, especially if you already have Homebrew as well.

Command to install Heroku via Homebrew

Now you should have all you need to get started. Login to Heroku from your terminal with this simple command:

You must login!

According to the Heroku documentation, “this authentication is required for both the heroku and git commands to work correctly.”

Now the real work begins. I am going to assume you already have a great visualization that you need to share with the world. If not, follow one of the tutorials I linked above. The data I am using is taken from IDEA’s voter turnout database.

You will need to convert your visualization into a .py file. You will need to pickle your dataframes and create some necessary files:

Procfile — a simple line of code to initialize your app with your py file

I broke this up into two lines so you could see the whole thing.

requirements.txt

Find your versions with the terminal command, “pip freeze”

runtime.txt

Your version of Python!

Once you have all these files in your repository, you are ready to deploy your app. While in your github repo, issue the command:

Create the app

You may specify the name of the app following create. Leave it blank and Heroku will name it for you. Finally, push your work to Heroku and it will host your code as its very own app.

Look for the url printed at the bottom.

The url issued will bring you to your active application. You can also follow the command below and it will do the same thing.

Simple.

Now that your project has its very own website, feel free to share it with the world!