Skip to content

Instantly share code, notes, and snippets.

@nzbart
Last active March 18, 2020 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzbart/e59ee9c35a5460e052e93ff2694fd02c to your computer and use it in GitHub Desktop.
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/.
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