Summary Tab

Row

Confirmed cases

682,552

Deaths

27,778 (4.1%)

Column

Daily Cumulative Cases by Type (Bulgaria only)

Column

Regional Mortality

Comparison by Country

Row

Daily New Confirmed Cases

Row

Mortality Ratio (Countries with More than 100,000 Cases)

World Map

Column

World map of cases (use + and - icons to zoom in/out)

About

The COVID-19 Dashboard

This dashboard provides an overview of the Novel Coronavirus (COVID-19 / SARS-CoV-2) epidemic for Bulgaria and its surrounding countries. This dashboard is built with R using the R Makrdown and flexdashboard framework and was adapted from the dashboard of Rami Krispin, courtesy of Antoine Soetewey.

Code

The code for the dashboard is available on GitHub.

Packages

Data

The input data for this dashboard is the dataset available from the {coronavirus} R package.

The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.

---
title: "COVID-19 in Bulgaria"
author: '[Metodi Simeonov](https://www.linkedin.com/in/mesime/){target="_blank"}'
#runtime: shiny
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed

---

``` {css}

a {
    color: #ffffff;
    text-decoration: none;
}

.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.active>a:hover,.navbar-inverse .navbar-nav>.active>a:focus {
    color: #ffffff;
    background-color: black;
}

.navbar-inverse .navbar-nav>li>a:hover,.navbar-inverse .navbar-nav>li>a:focus {
    color: #ffffff;
    background-color: black;
}

.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.active>a:hover,.navbar-inverse .navbar-nav>.active>a:focus {
    color: #ffffff;
    background-color: black;
}

body {
    font-family: "Source Sans Pro",Calibri,Candara,Arial,sans-serif;
    font-size: 15px;
    line-height: 1.42857143;
    color: #ffffff;
}

.navbar-dark .navbar-brand, .navbar.navbar-inverse .navbar-brand {
    color: black;
}

.chart-title {
  background-color: black;
  color: white;
}

.chart-stage {
  background-color: black;
}

.section.sidebar {
  background-color: black;
}

.navbar.navbar-inverse {
  background-color: #18bc9c;
  box-shadow: 3px 3px 5px black;
}

.nav-tabs .nav-link.active, .nav-tabs>li>a.active {
    background-color:#18bc9c;
}

.navbar-dark .navbar-brand, .navbar.navbar-inverse .navbar-brand {
  color:white;
}

.navbar.navbar-inverse ul.nav.navbar-nav>li.active>a {
  color: #18bc9c;
}

.dashboard-column {
  background-color: #18bc9c;
}

.section {
  background-color: #18bc9c;
}

body {
  background-color:#18bc9c;
}

```

```{r setup, include=FALSE}

devtools::install_github("RamiKrispin/coronavirus", force = TRUE)

library(coronavirus)
library(flexdashboard)

#update_dataset()

#data(coronavirus)

`%>%` <- magrittr::`%>%`

#------------------ Parameters ------------------
# Set colors - https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "#012833" # rgba(1, 74, 95, 0.97)
active_color <- "#012833"
#recovered_color <- "deepskyblue"
death_color <- "#1f0601"

#------------------ Data ------------------
df <- coronavirus %>%
  dplyr::filter(country == "Bulgaria") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(
    names_from = type,
    values_from = total
  ) %>%
  #dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
  dplyr::mutate(country = trimws(country)) %>%
  dplyr::mutate(country = factor(country, levels = country))

df_daily <- coronavirus %>%
  dplyr::filter(country == "Bulgaria") %>%
  dplyr::group_by(date, type) %>%
  dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
  tidyr::pivot_wider(
    names_from = type,
    values_from = total
  ) %>%
  dplyr::arrange(date) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(active = confirmed - death) %>%
  dplyr::mutate(
    confirmed_cum = cumsum(confirmed),
    death_cum = cumsum(death),
    active_cum = cumsum(active)
  )

df1 <- coronavirus %>% dplyr::filter(date == max(date))

df_tree <- coronavirus %>%
  dplyr::filter(country == "Bulgaria" | country == "Romania" | country == "Greece" | country == "Serbia" | country == "North Macedonia") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases), .groups = "drop") %>%
  dplyr::mutate(type = ifelse(type == "confirmed", "confirmed", type),
                #type = ifelse(type == "recovered", "recovered", type),
                type = ifelse(type == "death", "death", type)) %>%
  tidyr::pivot_wider(names_from = type, values_from = total) %>%
  dplyr::mutate(Active = confirmed - death) %>%
  tidyr::pivot_longer(cols = -country, names_to = "type", values_to = "total")

```

# Summary Tab

## Row {data-width="350"}

### Confirmed cases {.value-box}

```{r}

valueBox(
  value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
  caption = "Total Confirmed Cases",
  icon = "fas fa-user-md",
  color = confirmed_color
)

```

### Deaths {.value-box}

```{r}

valueBox(
  value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
    round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
    "%)",
    sep = ""
  ),
  caption = "Death Cases / Death Rate",
  icon = "fa-cross",
  color = death_color
)

```

## Column {data-width="400"}

### **Daily Cumulative Cases by Type** (Bulgaria only)

```{r}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(
    x = ~date,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    name = "Confirmed",
    line = list(color = active_color),
    marker = list(color = active_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~death_cum,
    type = "scatter",
    mode = "lines+markers",
    name = "Death",
    line = list(color = death_color),
    marker = list(color = death_color)
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-11"),
    y = 3,
    text = paste("First Death"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -90,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-13"),
    y = 14,
    text = paste(
      "Lockdown"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) %>%
  plotly::layout(
    paper_bgcolor = "#ffffff", # change this hex to modify background color
    plot_bgcolor  = "#ffffff",  # change this hex to modify background color
    title = "",
    yaxis = list(title = ""),
    xaxis = list(title = ""),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )

```

## Column {data-width="400"}

### **Regional Mortality**

```{r daily_summary}

daily_confirmed_deaths <- coronavirus %>%
  dplyr::filter(type == "death") %>%
  dplyr::filter(date >= "2020-03-07") %>%
  dplyr::mutate(country = country) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(cases)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total)

#----------------------------------------

# Plotting the data

daily_confirmed_deaths %>%
  plotly::plot_ly(colors = "BrBG") %>%
  plotly::add_trace(
    x = ~date,
    y = ~Bulgaria,
    marker = list(color = "#9119b8"),
    line = list(color = "#9119b8"),
    type = "scatter",
    mode = "lines+markers",
    name = "Bulgaria"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Romania,
    marker = list(color = "#07108a"),
    line = list(color = "#07108a"),
    type = "scatter",
    mode = "lines+markers",
    name = "Romania"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~`North Macedonia`,
    marker = list(color = "#044a00"),
    line = list(color = "#044a00"),
    type = "scatter",
    mode = "lines+markers",
    name = "N.Macedonia"
  ) %>%
    plotly::add_trace(
    x = ~date,
    y = ~Serbia,
    marker = list(color = "#4a0000"),
    line = list(color = "#4a0000"),
    type = "scatter",
    mode = "lines+markers",
    name = "Serbia"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Greece,
    marker = list(color = "#00a6a3"),
    line = list(color = "#00a6a3"),
    type = "scatter",
    mode = "lines+markers",
    name = "Greece"
  ) %>%
  plotly::layout(
    paper_bgcolor = "#ffffff", # change this hex to modify background color
    plot_bgcolor  = "#ffffff",  # change this hex to modify background color
    title = "",
    legend = list(x = 1, y = 0.9),
    yaxis = list(title = ""),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      b = 10,
      t = 10,
      pad = 2
    )
  )
  
```

# Comparison by Country

## Row {data-width="350"}

### **Daily New Confirmed Cases**

```{r}

daily_confirmed <- coronavirus %>%
  dplyr::filter(type == "confirmed") %>%
  dplyr::filter(date >= "2020-03-07") %>%
  dplyr::mutate(country = country) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(cases)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total)

#----------------------------------------

# Plotting the data

daily_confirmed %>%
  plotly::plot_ly(colors = "Accent") %>%
  plotly::add_trace(
    x = ~date,
    y = ~Bulgaria,
    marker = list(color = "#9119b8"),
    line = list(color = "#9119b8"),
    type = "scatter",
    mode = "lines+markers",
    name = "Bulgaria"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Romania,
    marker = list(color = "#07108a"),
    line = list(color = "#07108a"),
    type = "scatter",
    mode = "lines+markers",
    name = "Romania"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~`North Macedonia`,
    marker = list(color = "#044a00"),
    line = list(color = "#044a00"),
    type = "scatter",
    mode = "lines+markers",
    name = "N.Macedonia"
  ) %>%
    plotly::add_trace(
    x = ~date,
    y = ~Serbia,
    marker = list(color = "#4a0000"),
    line = list(color = "#4a0000"),
    type = "scatter",
    mode = "lines+markers",
    name = "Serbia"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Greece,
    marker = list(color = "#00a6a3"),
    line = list(color = "#00a6a3"),
    type = "scatter",
    mode = "lines+markers",
    name = "Greece"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 1, y = 0.9),
    yaxis = list(title = ""),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      b = 10,
      t = 10,
      pad = 2
    )
  )

```

## Row

### **Mortality Ratio** (Countries with More than 100,000 Cases)

```{r}

coronavirus %>% 
  
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total_cases = sum(cases)) %>%
  tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
  dplyr::arrange(- confirmed) %>%
  dplyr::filter(confirmed >= 100000) %>%
  dplyr::mutate(#recover_rate = recovered / confirmed,
                death_rate = death / confirmed) %>% 
  dplyr::mutate(#recover_rate = dplyr::if_else(is.na(recover_rate), 0, recover_rate),
                death_rate = dplyr::if_else(is.na(death_rate), 0, death_rate)) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(confirmed_normal = as.numeric(confirmed) / max(as.numeric(confirmed))) %>%
  plotly::plot_ly(#y = ~ round(100 * recover_rate, 1),
                  x = ~ round(100 * death_rate, 1),
                  size = ~  log(confirmed),
                  sizes = c(5, 70),
                  colors = "Dark2", # color param for the graph
                  type = 'scatter', mode = 'markers',
                  color = ~ country,
                  marker = list(sizemode = 'diameter' , opacity = 0.5),
                  hoverinfo = 'text',
                  text = ~paste("", country, 
                                " Confirmed Cases: ", confirmed,
                                #" Recovery Rate: ", paste(round(100 * recover_rate, 1), "%", sep = ""),
                                " Death Rate: ",  paste(round(100 * death_rate, 1), "%", sep = ""))
                 ) %>%
   plotly::layout(title = "",
     yaxis = list(title = "", ticksuffix = "%"),
                 xaxis = list(title = "", ticksuffix = "%",
                              dtick = 1,
                              tick0 = 0),
                 hovermode = "compare")

```

```{r}

### **Recovery / Death Ratio**

# coronavirus %>%
# 
#   dplyr::filter(country == "Bulgaria" | country == "Romania" | country == "Greece" | country == "North Macedonia") %>%
#   dplyr::group_by(country, type) %>%
#   dplyr::summarise(total_cases = sum(cases)) %>%
#   tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
#   dplyr::arrange(- confirmed) %>%
#   # dplyr::mutate(recover_rate = confirmed,
#   #               death_rate = death / confirmed) %>%
#   # dplyr::mutate(recover_rate = dplyr::if_else(is.na(recover_rate), 0, recover_rate),
#   #               death_rate = dplyr::if_else(is.na(death_rate), 0, death_rate)) %>%
#   dplyr::ungroup() %>%
#   dplyr::mutate(confirmed_normal = as.numeric(confirmed) / max(as.numeric(confirmed))) %>%
#   plotly::plot_ly(y = ~ round(100 * recover_rate, 1),
#                   x = ~ round(100 * death_rate, 1),
#                   size = ~  log(confirmed),
#                   sizes = c(5, 70),
#                   type = 'scatter', mode = 'markers',
#                   color = ~ country,
#                   marker = list(sizemode = 'diameter' , opacity = 0.5),
#                   hoverinfo = 'text',
#                   text = ~paste("", country,
#                                 " Confirmed Cases: ", confirmed,
#                                 " Recovery Rate: ", paste(round(100 * recover_rate, 1), "%", sep = ""),
#                                 " Death Rate: ",  paste(round(100 * death_rate, 1), "%", sep = ""))
#                  ) %>%
#   plotly::layout(yaxis = list(title = "Recovery Rate", ticksuffix = "%"),
#                 xaxis = list(title = "Death Rate", ticksuffix = "%",
#                              dtick = 1,
#                              tick0 = 0),
#                 hovermode = "compare")
```

# World Map

## Column {data-width="400"}

### **World map of cases** (*use + and - icons to zoom in/out*)

```{r}

# map tab by Art Steinmetz

library(leaflet)
library(leafpop)
library(purrr)

cv_data_for_plot <- coronavirus %>%
  dplyr::filter(cases > 0) %>%
  dplyr::group_by(country, province, lat, long, type) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::mutate(log_cases = 2 * log(cases)) %>%
  dplyr::ungroup()

cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)

pal <- colorFactor(c("#4682B4", "#451208"), domain = c("confirmed", "death")) #, "recovered"))

map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)

names(cv_data_for_plot.split) %>%
  purrr::walk(function(df) {
    map_object <<- map_object %>%
      addCircleMarkers(
        data = cv_data_for_plot.split[[df]],
        lng = ~long, lat = ~lat,
        # label=~as.character(cases),
        color = ~ pal(type),
        stroke = FALSE,
        fillOpacity = 0.6,
        radius = ~log_cases,
        popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
          feature.id = FALSE,
          row.numbers = FALSE,
          zcol = c("type", "cases", "country", "province")
        ),
        group = df,
        # clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
        labelOptions = labelOptions(
          noHide = F,
          direction = "auto"
        )
      )
  })

map_object %>%
  addLayersControl(
    overlayGroups = names(cv_data_for_plot.split),
    options = layersControlOptions(collapsed = FALSE)
  )

```

# About

**The COVID-19 Dashboard**

This dashboard provides an overview of the Novel Coronavirus (COVID-19 / SARS-CoV-2) epidemic for Bulgaria and its surrounding countries. This dashboard is built with R using the R Makrdown and flexdashboard framework and was adapted from the dashboard of [Rami Krispin](https://ramikrispin.github.io){target="_blank"}, courtesy of [Antoine Soetewey](https://github.com/AntoineSoetewey){target="_blank"}.

**Code**

The code for the dashboard is available on [GitHub](https://github.com/Met0o/COVID){target="_blank"}.

**Packages**

-   Dashboard interface - [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/)
-   Visualization - [plotly](https://plot.ly/r/)
-   Data manipulation - [dplyr](https://dplyr.tidyverse.org/), [tidyr](https://tidyr.tidyverse.org/), and [purrr](https://purrr.tidyverse.org/)
-   Mapping - [leaflet](https://rstudio.github.io/leaflet/) and [leafpop](https://github.com/r-spatial/leafpop)

**Data**

The input data for this dashboard is the dataset available from the [`{coronavirus}`](https://github.com/RamiKrispin/coronavirus){target="_blank"} R package.

The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv){target="_blank"}.