Over the last 11 or so weeks, thanks in part to physical distancing, I have been exploring the R Shiny platform. For those unfamiliar with Shiny, this is the platform that was used to create the Monitoring COVID-19 In Canada dashboard. And spoiler alert for my future students – this is one of the tools that we are going to be using in Data Science this coming fall.
As I’ve written in previous posts, I have used statistics and data science to help manage some of the anxieties brought on by the COVID-19 pandemic. This has led to the co-development of Monitoring COVID-19 In Canada dashboard, as well as the creation of several animations and plots that I use to understand our current reality. None of it is perfect, but that’s to be expected given data limitations and given that we are learning new things about the disease every single day.
The pandemic has also provided me an opportunity to explore Shiny more completely. While I have known of and tinkered with Shiny for several years, my goal over the past few months was to better acquaint myself with Shiny by creating a dashboard that would allow me to compare Canadian COVID-19 data with that of other countries. This was partly due to my own curiosity, but also because of the numerous requests from folks who were curious about how well Canada was doing in comparison to other parts of the world.
Using the Monitoring COVID-19 In Canada dashboard as a model, I set out to create another tool. While I won’t go into detail about the ins and outs of building a Shiny dashboard, I will direct you to the R Shiny website because the tutorials provided there helped me immensely. I’d also recommend learning about Leaflet and building interactive maps for those of you who want to add some geo-visualizations to your site.
Working with Shiny was easy and straight forward. My biggest hurdle was wrapping my brain around the structure of an R Shiny app. That is, the code is divided into two major sections: the user interface, and the server.
- The user interface code allows you to create the layout of the page (including things like menus, sidebars, and panels), and to create interactive elements (such as sliders and drop down lists) that will automatically update the visualizations you’ve created with whatever data you are working with.
- The server code is where data can be summarized, transformed, analyzed, and turned into any number of plots you’d be able to generate using ggplot. This includes the mapping of geo-referenced data. It is also where inputs from the interactive elements that make up the user interface are translated into action that update the data the feed the visualizations you’ve created.
That’s it. That was the biggest hurdle. As you can see, that’s not really a big hurdle to get over. And to be honest, most of my time with Shiny has been spent creating specific plots, and formatting the site to look and feel the way I wanted it to.
The final result of my tinkering can be found here. For now, I’ve included the following visualizations:
- A map of confirmed cases, recovered cases, and deaths by country.
- Daily and cumulative plots of cases and deaths. Here you can select up to three countries to view at the same time. A LOESS trend curve is provided for each country as well. The cumulative plots also provide you the opportunity to use an exponential trend, however, for most countries this is no longer meaningful as they have moved beyond the initial exponential growth phase of the pandemic.
- Plots of the changing growth rate and doubling time for both cumulative cases and deaths. Again, up to three countries can be selected, and a LOESS trend curve is provided for each. The goal is to see the trend line for the growth rate go to zero, and the trend line for the doubling time increase.
- A stacked or percentage bar plot to show the change in the status of cumulative cases for a given country (i.e. confirmed case, recovered case, or death).
- The changing case fatality rate over time. Up to three countries can be compared.
- A bar chart that compares the cases and deaths for the 20 countries (with a population above 4 million) with the highest case and mortality counts. The plot can be converted to per capita as well.
- Finally, two plots – one for Canada and one for the United States – are provided that shows how the current observed number of deaths due to COVID-19 compare to the expected number of deaths due to other leading causes of death such as cancer, heart disease, diabetes, and more. These plots also indicate the date that the number of COVID-19 deaths surpassed the expected numbers from other causes. I’ve only created these for Canada and the United States so far, but could likely produce similar plots if I could find a consistent data set of leading causes of death in other countries.
As always, this is a work in progress that I expect to continue updating as more and better data are made available. And of course, regardless of what the plots here might suggest, please follow the advice of our public health experts.
Stay home if you can. Physically distance yourself. Wash your hands. Stay safe.
This dashboard was heavily influenced by the COVID-19 In Canada Dashboard that I co-created with Kurtis Sobkowich (PhD Student – Epidemiology, Ontario Veterinary College, University of Guelph), and Dr. Theresa Bernardo (IDEXX Chair in Emerging Technologies and Preventive Healthcare, Ontario Veterinary College, University of Guelph).