I’m going to preface this with: this is not a fast application by any means. It wasn’t built on some wix or paid per month hosting site, it’s all built in python and deployed through heroku — the free kind. So be patient if it doesn’t load right away — it will load!
I’ll be the first to admit — I’m not known for my design/artistic abilities. When I was younger, I use to like to draw castles, but that’s about the extent of it. Also, it wasn’t overly apparent that what I was drawing were castles either; I was told one looked like a barn once. This was before the age of the cell phone I mind you.
This article will attempt to describe my methods in creating and “designing” a United States-based Covid-19 dashboard with charts that you likely won’t find anywhere else. Being a data engineer and previously a data scientist, I don’t tend to find the typical charts asked for by exec level folks very interesting.
I won’t go over too much in this section — if you’re reading this, chances are you have your favorite IDE, you’ve at least heard of the words “deploy” and “heroku”, and thus may likely have also heard of “flask” and “dash”, so I won’t waste more of your time. We will be using Python3, Plotly.js, Dash, Atomand heroku. Take it or leave it!
As mentioned in the few sentences at the top of the dashboard, the source comes from this link: https://covidtracking.com/api/v1/us/daily.csv Import this into a dataframe in your notebook and move on.
#Server certificate verification by default has been
# introduced to Python recently (in 2.7.9).
# This protects against man-in-the-middle attacks,
# and it makes the client sure that the server is indeed who it
# claims to be.
# if the first execution doesn't run, just run it again.
import os, ssl
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and
getattr(ssl, '_create_unverified_context', None)):
ssl._create_default_https_context = ssl._create_unverified_context
There weren’t too many libraries used in this application, despite what pip freeze > requirements.txt
says. The main libraries used in order to get the notebook up and running are:
import dash # (version 1.12.0) pip install dash
import dash_table
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import pandas as pd
import plotly
import numpy as np
# import seaborn as sns
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import plotly.figure_factory as ff
import csv
from urllib.request import urlopen
import urllib.request
Run the above code and then run the following code and you should be good:
url = "https://covidtracking.com/api/v1/us/daily.csv"df = pd.read_csv(url)
df.head()
#covid19 #heroku #plotly #dash #python #programming