knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(c19euxplorer)
c19euxplorer
features a Shiny app to explore the data of COVID-19 related variables in several countries in Europe. The variables covered are daily and cumulative cases and deaths, weekly testing and positivity rate, weekly dominant source of transmission, and daily community mobility during the pandemic. This package also contains several other functions to simplify the codes used in the app.
The app's sources of data are the European Centre of Disease Prevention and Control and the Google Community Mobility Report. The cumulative figures and GCMR are downloaded with the tidycovid19 R package.
The main purpose if this app is a container of a Shiny app package to explore COVID-19 related variables in several countries in Europe. To use this feature, you can use the launch_app function.
#> launch the app #> make sure to have all of the packages in suggest installed launch_app()
The launched app would appear as follow:
knitr::include_graphics("https://datain360.com/posts/2020-10-14-shinyselfreview/shiny_gif/my_shiny.gif")
This app comprises of seven tabs as follow:
library(tibble) tibble(c19euxplorer::testing_weekly_eu)
tibble(c19euxplorer::transmission_subnational_level)
Country Centroids Data
Besides those two data sets, I also embedded a country centroids data set. Apart from COVID-19 matter, this data set is useful if you wish to make a bubble map with a point represents a whole country, such as the following map:
tibble(c19euxplorer::country_centroids)
library(dplyr) library(ggplot2) library(maps) library(viridis) library(viridisLite) #> data to be mapped plot <- testing_weekly_eu #> country centroid centro <- country_centroids %>% rename(country = name_long) #> join the those two data sets pop_map <- left_join(plot, centro, by = "country") %>% filter(year_week == "2020-W20") #> load world map world_map <- map_data("world")
#>the map ggplot() + geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "#73C6B6", colour = "white", alpha = 0.7 ) + geom_point(data = pop_map, aes(x = Longitude, y = Latitude, colour = population, size = population, alpha = population)) + scale_size_continuous(range = c(1, 6)) + scale_color_viridis(option = "inferno", trans = "log") + scale_alpha_continuous(trans = "log") + guides(colour = guide_legend()) + xlab("") + ylab("") + theme(panel.grid = element_blank(), axis.title = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(), plot.background = element_rect(fill = "white"), panel.background = element_rect(fill = "white")) + labs(title = "Population Bubble Map")
daily_indicator()
This function aims to simplify the code in c19euxplorer
shiny app by selecting country, date, and indicators in daily data to be visualized in Cases and Deaths tab. This function would be used in the app, although you can also use this function outside the app. However, make sure to have these variables (with the exact same name) in your data frame in order to make the function works.
plot_daily <- plot %>% rename(daily_cases = new_cases, date = year_week) plot_daily_new <- daily_indicator(plot_daily, "Cases") tibble(plot_daily_new)
getplot()
Here, I would give you an example of the usage of getplot()
function. We could use plot_cumulative
to make a plot. However, since there are a lot of countries, we would like to choose only several countries.
library(lubridate) for_plot <- plot_daily_new %>% mutate(week_only = as.numeric(sub(".*W", "", date))) %>% filter(country %in% c("Austria", "Spain", "United Kingdom")) %>% mutate(date = as.Date(paste(2020, week_only, 1, sep="-"), "%Y-%U-%u")) getplot(for_plot)
getref()
Currently, I have not found a package that facilitate the creation of reference in Shiny. So, I made this function to make the reference writing come in handy.
Using the HTML tag provided by Shiny, you have to type this code to create a reference like this:
tags$li(class = "li-custom", "Winston Chang. (2018).", tags$a(href = "https://CRAN.R-project.org/package=shinythemes", "shinythemes: Themes for Shiny", class = "externallink"))
Winston Chang. (2018). shinythemes: Themes for Shiny
With getref()
, you just have to type this:
getref("Winston Chang", "2018", "https://CRAN.R-project.org/package=shinythemes", "shinythemes: Themes for Shiny")
getlink()
Just like getref()
, getlink()
also aims to simplify the typing of link in Shiny app's UI using the HTML tag. Initially, Shiny has a markdown function to also make this task easier. However, markdown
adds the new hyperlink text into a new line. Sometimes, we want to use some hyperlink texts in one sentences.
Using HTML tag, you have to type this code to create this hyperlink text:
tags$a(href = "https://www.monash.edu/study/courses/find-a-course/2021/business-analytics-b6022?gclid=EAIaIQobChMI5bKC_Y-g7AIVzn8rCh3aQABbEAAYASAAEgK09PD_BwE&international=true#overview-1", "Master of Business Analytics", class = "externallink")
With getlink()
, you can just type this:
getlink("https://www.monash.edu/study/courses/find-a-course/2021/business-analytics-b6022?gclid=EAIaIQobChMI5bKC_Y-g7AIVzn8rCh3aQABbEAAYASAAEgK09PD_BwE&international=true#overview-1", "Master of Business Analytics")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.