19-05-2020

Introduction

Data Cleaning and Reformatting

This piece of code is to download data and subset the data with the desire range, and fill missing values with zeros.

library(tidyr)
library(plotly)
library(data.table)
df <- fread('https://opendata.ecdc.europa.eu/covid19/casedistribution/csv')
country_list<-c('Netherlands','Spain','Italy','United_States_of_America')
sub_set_data <- function(df,country_selection) {
     start_date=as.Date('2020-02-27')
     end_date=Sys.Date()-1
     df=setDF(df)
     df_sub<-df[df['countriesAndTerritories']==country_selection,] 
     df_sub_new<-df_sub %>%
          mutate(dateRep = as.Date(dateRep,format("%d/%m/%Y"))) %>%        
          complete(dateRep = seq.Date(start_date,end_date, by="day")) %>%
          filter(dateRep>=start_date & dateRep<=end_date)
     x=df_sub_new$dateRep
     y=df_sub_new$deaths
     y[is.na(y)]<-0
     return(list(x,y))
}

Generating Plot

The following code is to generate the time series plot for each selected country.

country_selection='Netherlands'
date<-sub_set_data(df,country_selection)[[1]]
          death<-sub_set_data(df,country_selection)[[2]]
          plot(x=date, 
               y=death,
               type="l",
               col="red")

About the App

There is a side panel and main panel in the app.

In the side panel on the left there is a dropdown manu to let the users to select which country they would like to view. After selecting the country, the plot will show immediately in the main panel on the right.

Many thanks for your time!

Be safe and stay healthy!