Last active
March 18, 2020 07:31
-
-
Save nzbart/e59ee9c35a5460e052e93ff2694fd02c to your computer and use it in GitHub Desktop.
New Zealand coronavirus/COVID-19 case chart as Shiny app. Published at https://bartj.shinyapps.io/covid19/.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(tidyverse) | |
library(lubridate) | |
library(plotly) | |
library(scales) | |
ui <- shiny::fillPage( | |
titlePanel("Coronavirus in NZ"), | |
mainPanel( | |
plotlyOutput(outputId = "casesOverTime") | |
) | |
) | |
server <- function(input, output) { | |
output$casesOverTime <- renderPlotly({ | |
url <- 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv' | |
raw <- readr::read_csv(url, col_types = cols( | |
.default = col_integer(), | |
`Province/State` = col_character(), | |
`Country/Region` = col_character(), | |
Lat = col_double(), | |
Long = col_double() | |
)) | |
nz <- raw %>% | |
filter(`Country/Region` == "New Zealand") %>% | |
select(-`Province/State`, -Lat, -Long) %>% | |
pivot_longer(-`Country/Region`) %>% | |
mutate(DateNzLocal = lubridate::parse_date_time(name, orders="mdy") %>% as.Date) %>% | |
rename(NumberOfCases = value) %>% | |
select(DateNzLocal, NumberOfCases) | |
plot <- ggplot(nz) + | |
geom_line(aes(x = DateNzLocal, y = NumberOfCases)) + | |
labs ( | |
x = "Date, NZ", | |
y = "Cumulative number of cases", | |
title = "Number of positive COVID-19 cases in New Zealand", | |
subtitle = "Data source: https://github.com/CSSEGISandData" | |
) + | |
scale_y_continuous(breaks = pretty_breaks()) | |
ggplotly(plot) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment