Giter Club home page Giter Club logo

coronavirus_dashboard's Introduction

Hi there, I'm Rami

I'm a senior data science and engineering manager, author ๐Ÿ“, open-source contributor ๐Ÿ› ๏ธ, Docker Captain ๐Ÿณ, and LinkedIn Instructor. I mainly write code with Python, R and bash, occasionally I do HTML, CSS, and trying to learn JavaScript and Julia.

I enjoy teaching about data science in production, MLOps, and Docker. You can find some of my tutorials on GitHub (see tutorial sections below) and Medium, and LinkedIn Newsletter. I recently released a course - Data Pipeline Automation with GitHub Actions Using R and Python with LinkedIn Learning.

Here is some of the stuff I enjoy doing:

  • Time series analysis and forecasting
  • Put stuff in production
  • Work with data and APIs
  • Machine learning
  • Bayesian statistic
  • Data visualization
  • Maps

๐Ÿ”— ย I am also on:

ramikrispin rami.krispin ramikrispin

Main projects

Courses

Could not find the repo

Books

atsaf Hands-On-Time-Series-Analysis-with-R

Tools for time series analysis and forecasting, and datasets:

TSstudio UKgrid USgrid USgas sfo EIAapi NYgrid

Tutorials

vscode-python vscode-r ai-dev-2024-ml-workshop useR2024-pipeline-workshop vscode-python vscode-r ollama-poc lang2sql Introduction-to-Docker deploy-flex-actions shinylive-r shinylive awesome-ds-setting

coronavirus_dashboard's People

Contributors

dependabot[bot] avatar ramikrispin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coronavirus_dashboard's Issues

Recovered cases

Dear Rami, do you expect to edit the code given that the recovered cases have been removed from the dataset since March 23rd?

Death rate for closed cases not obvious in the dashboard application.

The dashboard application is great for showing the death rate based on the total number of cases. But it is not so great at showing the death rate for the closed number of cases...

Closed Cases = Deaths + Recoveries

The total number of cases includes individuals who are still sick and I don't want to see the data that includes outcomes that are still pending. So I would like to suggest adding two possible options for visualizing the death rate:

Option 1 shows mortality rate for total cases. i.e. (Deaths / Confirmed cases) * 100
Option 2 shows mortality rate for closed cases i.e. (Deaths / Closed Cases ) * 100

Should be able to achieve Option 2 by eliminating all of the Active cases. Also, it would also be nice to see that data without China.

Error in validateCssUnit(sizeInfo$width) :

Greetings,

I am using your codes modified by Antoine Soetewey to create a New Dashboard for Haiti as this country lacks a good dashboard
https://statsandr.com/blog/how-to-create-a-simple-coronavirus-dashboard-specific-to-your-country-in-r/

When knitting to flexdashboard I am getting the following error:

Quitting from lines 156-185 (Haiti-Coronavirus-Dashboard.Rmd)
Error in validateCssUnit(sizeInfo$width) :
CSS units must be a single-element numeric or character vector
Calls: ... -> need_screenshot -> toHTML -> validateCssUnit
In addition: Warning message:
package 'flexdashboard' was built under R version 4.0.3
Execution halted

I am using RStudio Version 1.3.1093. Do you have an idea why I am getting this error message and how to fix it. I would be very grateful to you.

The codes are below:

Best,

Patrick


title: "Coronavirus in Haiti"
author: "Patrick Stephenson"
output:
flexdashboard::flex_dashboard:
orientation: rows
# social: ["facebook", "twitter", "linkedin"]
source_code: embed
vertical_layout: fill

#------------------ Packages ------------------
library(flexdashboard)
# install.packages("devtools")
# devtools::install_github("RamiKrispin/coronavirus", force = TRUE)
library(coronavirus)
data(coronavirus)
# View(coronavirus)
# max(coronavirus$date)
`%>%` <- magrittr::`%>%`
#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
#------------------ Data ------------------
df <- coronavirus %>%
  # dplyr::filter(date == max(date)) %>%
  dplyr::filter(country == "Haiti") %>%
  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(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = dplyr::if_else(country == "United Arab Emirates", "UAE", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
  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 == "Haiti") %>%
  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 - recovered) %>%
  dplyr::mutate(active = confirmed - death) %>%
  dplyr::mutate(
    confirmed_cum = cumsum(confirmed),
    death_cum = cumsum(death),
    # recovered_cum = cumsum(recovered),
    active_cum = cumsum(active)
  )
df1 <- coronavirus %>% dplyr::filter(date == max(date))

Summary

Row {data-width=400}

confirmed {.value-box}

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

death {.value-box}

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 = "fas fa-heart-broken",
  color = death_color
)

Row

Daily cumulative cases by type (Haiti only)

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(
    x = ~date,
    # y = ~active_cum,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    # name = "Active",
    name = "Confirmed",
    line = list(color = active_color),
    marker = list(color = active_color)
  ) %>%
  
  # plotly::add_annotations(
  #   x = as.Date("2020-02-04"),
  #   y = 1,
  #   text = paste("First case"),
  #   xref = "x",
  #   yref = "y",
  #   arrowhead = 5,
  #   arrowhead = 3,
  #   arrowsize = 1,
  #   showarrow = TRUE,
  #   ax = -10,
  #   ay = -90
  # ) %>%
  
  plotly::layout(
    title = "",
    yaxis = list(title = "Cumulative number of cases"),
    xaxis = list(title = "Date"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )

Comparison

Column {data-width=400}

Daily new confirmed cases

daily_confirmed <- coronavirus %>%
  dplyr::filter(type == "confirmed") %>%
  dplyr::filter(date >= "2020-02-29") %>%
  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() %>%
  plotly::add_trace(
    x = ~date,
    y = ~Haiti,
    type = "scatter",
    mode = "lines+markers",
    name = "Haiti"
  ) %>%
  # plotly::add_trace(
  #   x = ~date,
  #   y = ~France,
  #   type = "scatter",
  #   mode = "lines+markers",
  #   name = "France"
  # ) %>%
  # plotly::add_trace(
  #   x = ~date,
  #   y = ~Spain,
  #   type = "scatter",
  #   mode = "lines+markers",
  #   name = "Spain"
  # ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~`Dominican Republic`,
    type = "scatter",
    mode = "lines+markers",
    name = "Dominican Republic"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Jamaica,
    type = "scatter",
    mode = "lines+markers",
    name = "Jamaica"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Cuba,
    type = "scatter",
    mode = "lines+markers",
    name = "Cuba"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.7, y = 0.9),
    yaxis = list(title = "New confirmed cases"),
    xaxis = list(title = "Date"),
    # paper_bgcolor = "black",
    # plot_bgcolor = "black",
    # font = list(color = 'white'),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )

Cases distribution by type

df_EU <- coronavirus %>%
  # dplyr::filter(date == max(date)) %>%
  dplyr::filter(country == "Haiti" |
    country == "Dominican Republic " |
    country == "Jamaica" |
    country == "Cuba") %>%
  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(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = dplyr::if_else(country == "United Arab Emirates", "UAE", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
  dplyr::mutate(country = trimws(country)) %>%
  dplyr::mutate(country = factor(country, levels = country))
plotly::plot_ly(
  data = df_EU,
  x = ~country,
  # y = ~unrecovered,
  y = ~ confirmed,
  # text =  ~ confirmed,
  # textposition = 'auto',
  type = "bar",
  name = "Confirmed",
  marker = list(color = active_color)
) %>%
  plotly::add_trace(
    y = ~death,
    # text =  ~ death,
    # textposition = 'auto',
    name = "Death",
    marker = list(color = death_color)
  ) %>%
  plotly::layout(
    barmode = "stack",
    yaxis = list(title = "Total cases"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )

Map

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

# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>%
  # dplyr::filter(country == "Haiti") %>%
  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("orange", "red", "green"), 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.8,
        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 Coronavirus Dashboard: the case of Haiti

This Coronavirus dashboard: the case of Haiti provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for Haiti. This dashboard is built with R using the R Makrdown framework and was adapted from this dashboard{target="_blank"} by Rami Krispin.

Code

The code behind this dashboard is available on GitHub{target="_blank"}.

Data

The input data for this dashboard is the dataset available from the {coronavirus}{target="_blank"} R package. Make sure to download the development version of the package to have the latest data:

install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")

The raw data is pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository{target="_blank"}.

Information

More information about this dashboard (and how to replicate it for your own country) can be found in this article.

Update

The data is as of r format(max(coronavirus$date), "%A %B %d, %Y") and the dashboard has been updated on r format(Sys.time(), "%A %B %d, %Y").


Go back to statsandr.com (blog) or antoinesoetewey.com (personal website).

Warning messages

this is great and I never see this before, and so nice project, and could you please figure the following below, thanks.

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(title = "Recovery / Death Ratio (Countries with More than 20,000 Cases)",
yaxis = list(title = "Recovery Rate", ticksuffix = "%"),
xaxis = list(title = "Death Rate", ticksuffix = "%",
dtick = 1,
tick0 = 0),
hovermode = "compare")

Warning messages:
1: In RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

2: In RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Error running the dashboard on my Shinyserver

Hi Rami,
I forked your dashboard on my R server/Shiny.
I'm trying to run your dashboard but I got an error here in my shiny log:


su: ignoring --preserve-environment, it's mutually exclusive with --login

Listening on http://127.0.0.1:39235
Warning: Error in value[[3L]]: Couldn't normalize path in addResourcePath, with arguments: prefix = 'leaflet-providers-1.9.0'; directoryPath = '/tmp/RtmpFpS8yQ'
108: stop
107: value[[3L]]
106: tryCatchOne
105: tryCatchList
104: tryCatch
103: addResourcePath
102: FUN
101: lapply
100: processDeps
99: transform
98: func
96: f
95: Reduce
86: do
85: hybrid_chain
84: origRenderFunc
83: output$reactivedoc
3:
1: rmarkdown::run

Have you any suggestion?
Thanks
Pasquale

ps. Stay safe

Provide a guide of how to run the dashboard

First of all, I want to truly thank you, for this marvelous work but I have a small issue that is encountered by me and maybe by others also. I simply can't run the project to see the results on R studio or the browser or something.

I'm not an R developer but the dashboard looks very useful to be used and customized and I believe this is your intention when you posted this project to the open-source community.

So it will be great to provide a small section of how to install R and run the dashboard.

Cheers.

Question about how I can implement auto update

Hi Rami! This project is super. Thanks for sharing it.

I was wondering if you could share some pointers on how I could make my dashboard auto-update as well. I saw that you have a bash script that github workflows will run in order to run the r markdown file through a cron job. However, I saw you had a docker image as well, which I believe is for R to run. May I ask how I would go about creating a docker image? Is that the only way?

Cheers.

Error: Assigned data

Hi,

I want to try the dashboard.
When i run it on R studio i got this error

#------------trajectory plot data prep------------

df_china <- coronavirus %>% dplyr::filter(type == "confirmed", Country.Region == "China") %>%

  • dplyr::group_by(date) %>%
  • dplyr::summarise(cases = sum(cases)) %>%
  • dplyr::ungroup() %>%
  • dplyr::arrange(date) %>%
  • dplyr::mutate(china = cumsum(cases)) %>%
  • dplyr::filter(china > 100) %>%
  • dplyr::select(-cases, -date)

df_china$index <- 1:nrow(df_china)
Error: Assigned data 1:nrow(df_china) must be compatible with existing data.
x Existing data has 0 rows.
x Assigned data has 2 rows.
โ„น Only vectors of size 1 are recycled.

can you help me?

Upcoming changes in the coronavirus package (v0.2.0 CRAN)

As the many changes occurred since the release of v0.1.0 significant changes in the data structure expected in v0.2.0 (expected to release to CRAN by May 15. Changes are available on the dev-v020 branch

coronavirus 0.2.0

  • Data changes:
    • coronavirus dataset - Change the structure of the US data from March 23rd, 2020 and forward. The US data is now available on an aggregated level. More information about the changes in the raw data available on this issue
    • Changes in the columns names and order:
      • Province.State changed to province
      • Country.Region changed to country
      • Lat changed to lat
      • Long changed to long
    • The covid_south_korea and covid_iran that were avialble on the dev version were removed from the package and moved to new package covid19wiki, for now available only on Github

How do you set up the Autoupdate Dashboard?

From looking at the commit history, I can see that daily commits are being pushed to update the data on the dashboard website. What I would like to ask is: how do you set this up to happen automatically, and do you need to have a computer at home that is always turned on during the update schedule to make sure it autoupdates?

I like your portfolio website and I followed you on GitHub.

update data

Case for haiti is not update.

Can you help me install the script and use Health Ministry to update info for Haiti.

And also I want Haiti to be the first country that appear on the map, since I wanted to informed them first about the spreading of the virus.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.