10.3. Dashboards¶
Tip
One awesome thing you can do with data: Build a dashboard!
Not only are dashboards cool as hell, but building them is also a good way to show off your skills (e.g. put them on your resume). Dashboards can be really useful for real-world decision-makers in business and government settings.
My current “go-to” recommendation for making AND deploying apps is streamlit
:
The Hall of Awesomeness has an example of a cool streamlit dashboard
The guide to make that is here.
Official docs here, I reviewed the “main concepts” and “create an app” pages and went from there
How do you think this amazing page was built? Or the interactive visualizations 538, NYT, WaPo, WSJ, and others frequently publish?
What do you need? Mostly: Data acquisition and formatting skills - which you have!
The main hiccup: GitHub Pages can create a website out of a Jupyter notebook, but it’s just a static image of the file. People looking at the site will just see whatever it looked like at the time you last saved the file, so there is no interactivity and visitors can’t adjust inputs and rerun it. I am not a web dev, and you probably aren’t either, so below I discuss (1) free options (2) that reduce the web dev pain (3) as of late 2022.
Part 1: Make it work on your computer
The first thing is to build your dashboard/app so it works on your computer. Basically, you’ll make a notebook file and then convert it to a webpage.
I suggest looking around to see if anyone has made an app/dashboard like what you want, using a given package I list below. (Meaning: Layout choices, similar element types, interactivity.) Then emulate the code for that and tweak it to your needs.
Many packages are designed to produce full featured dashboards, apps, and widgets. My current rough pecking order:
streamlit
- see some examples here. Deploying the app to a website is easy as heck and free as long as traffic to the site is low.dash
- highly flexible, usesplotly
for visualsgradio
shiny
- deployment is easy, but because the package is still in development, things might change.
For simpler applications and dashboards, you can write a Jupyter notebook file, and make it so that the file itself produces what you want shown on the website. This lets you output plotly
and seaborn
graphs you’re familiar with. To add interactivity, choose one route below:
ipywidgets
: Probably a little more coding than mercury and resulting page will have inputs above outputs, but you avoid Mercury’s opinionated formatting for the website. Walkthrough here.ipywidgets
+voila
:voila
converts the notebook into a dashboard. Look at the examples here and docs here.
Note
To make your website faster, you want it to load the smallest dataset possible and do as little data processing as required. This means you do all the preprocessing steps (everything right up until user input is needed) in a separate file that saves this as a dataset. Then, your app can start by loading this and continuing.
Also, because we want free, the hosting service you choose in Part 2 will impose limits on how much data you can load and how computationally intensive your app can be. So try to imagineer your dashboard with that in mind.
Part 2: Deploy it so others can find it on the web
Note
Note: If you Google, you’ll see lots of walkthroughs using “Heroku.” This service is no longer completely free.
Now, you need to “deploy” it so that it is a website people can visit and interact with. This step depends on how you built your app:
If
shiny
: shiny handles it!If
streamlit
: Can usestreamlit
’s hosting (easy, and free as long as traffic to the site is low)If
streamlit
orgradio
: Walkthrough You can upload the app to huggingface.co, which probably has better performance than streamlit’s free service. After you have your app on huggingface, you can easily embed the app inside a GitHub page, which you know how to create and customize to your liking!If
mercury
: You can also take the huggingface route, but slightly different steps.If
dash
1:PythonAnywhere (see here)
fly.io but you’ll need to “dockerize” your app for fly.io
If
ipywidgets
oripywidgets
+voila
:binder makes notebooks on GitHub an interactive file anyone on the web can use. You just get the binder link and put it on your person site so people can find your app.
Any of the suggestions under
dash
can work too.
If you ever build one, PLEASE send it to me!
- 1
My previous suggestion to deploy
dash
was Heroku, but it is not completely free anymore. (It offers a free plan for students for 12 months.) A written walkthrough to build this page. And a good video showing different approaches based on the data needs of your site.