COVID Countdown! Building a Shiny Dashboard to Track Vaccinations in Canada

The Government of Canada has stated that “the majority” of Canadians should be vaccinated against COVID-19 by September of 2021, and PM Trudeau doubled down on this statement in late January. So how’s it going so far?

To figure it out, I built an interactive dashboard that shows how many vaccinations have been given across Canada and the provinecs, and predicts how long it will take to finish the job at the rate we’re going.

The results are… well, take a look for yourself.

The rest of this post is a high-level discussion of how I put the dashboard together, in case anyone would like to make their own.

You can check out the code on Github here.

The code framework: shiny, shinydashboard, the tidyverse, and plotly

I work primarily in R, so I decided to build this dashboard using the shiny and shinydashboard packages. If you’re not familiar, these packages make it pretty easy to turn an R-based data science/data analysis project into an interactive web app. The shinydashboard package takes shiny’s basic approach adds some neat features like tabs, sidebars, and other fun stuff.

For examples of what you can do with R and shiny, check out my interactive COVID-19 physical distance simulation or my [NLP model that predicts customer ratings from review texts](/post/a-fast-effective-and-simple-classification-model-for-customer-reviews/.

I’m a big fan of the tidyverse suite of packages and their general approach to wrangling and problem-solving, so they were a natural fit.

Finally, I decided to use plotly to generate interactive visualizations. Interactivity plots give web apps some real extra “oomph,” and I appreciate how the plotly::ggplotly() function makes it easy to take standard ggplot2 visualizations and make them interactive.

The data: covid19tracker.ca

All the data comes from one most excellent source: the COVID-19 Tracker Canada Project. It’s available through a public API that’s very easy to use, and their documentation is great! (I actually found their API first, and then got the idea for the dashboard after.)

The logic of the app

The data analysis part of the app is pretty simple. It’s roughly:

  • Check how long since we updated the data. If it’s been more than 4 hours, do a refresh and store the data locally. (This is so we don’t spam covid19tracker.ca’s servers.)
  • For each region, get the first vaccination date, the number so far, the average vaccinations per minute, and the total number required.
  • Then figure out when we’ll hit that target.

It does all of this math on start-up. Then the drop-down menus just let you filter the data for a specific jurisdiction, and choose the time zone in which you’d like to receive your depressing prediction. This is a Canada-wide app, after all!1

Web hosting

I’m hosting the open-source version of shiny-server on an Amazon Web Services machine, specifically a t2.micro AWS EC2 instance running Ubnutu, the smallest (and free-est) option. I’m using a docker image called rocker/shiny-verse, because–and no guides online mentioned this–I wasn’t able to install shiny as usual on the t2.micro: it kept crashing when compiling httpuv. I guess I could have paid 25 cents to get some extra RAM for as long as it took to install, but docker solved the problem for now.

The crux: Dark humour as a call to action

The basic idea is: how long will it actually take to reach our stated vaccination targets if we continue at our current rate?

The general narrative I’ve been seeing is that vaccines are unequivocally good news, and that things are overall going great, or at least going. Sure, there have been supply setbacks, but we’re getting those numbers up every day and we’re going to meet our end-of-September goal.

But are we? Are we really? Enter this dashboard, to give a sobering and evidence-based answer.

And as of February 2, 2021, it looks like we won’t. To be clear I really, really, really hope we do hit our targets. But we’re not going to get there through limp assertions and cynically performative optimism. If things suck, we need to know about it now so that we can work on them.


  1. Yes, I hear you and I agree, if it’s truly a Canadian product il serait meilleur d’avoir un version francais aussi. Je suis sur que c’est assez clair que je ne pourrais pas le faire moi-meme, donc lancez-moi un courriel si vous voulez m’aider avec une traduction!↩︎

Christopher Belanger, PhD MBA
Christopher Belanger, PhD MBA
Data Scientist
Researcher
Policy Expert

My research interests include data science, marketing, and public policy, bridging the quantitative-qualitative divide.

comments powered by Disqus

Related