Skip to content

Instantly share code, notes, and snippets.

@benjaminrobinson
Last active September 12, 2020 23:19
Show Gist options
  • Save benjaminrobinson/33969b414f537443f3f0042b0b2273d8 to your computer and use it in GitHub Desktop.
Save benjaminrobinson/33969b414f537443f3f0042b0b2273d8 to your computer and use it in GitHub Desktop.
Thomas More University COVID-19 Dashboard
library(tidyverse)
library(rvest)
# library(hrbrthemes)
# library(ggimage)
# library(ggrepel)
# library(ggthemes)
library(shiny)
library(plotly)
'https://www.thomasmore.edu/covid-19/healthy-at-thomas-more-plan/covid-19-dashboard/' %>%
read_html %>%
html_table -> dat
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSxPaT5y2JjemzHzibShDMpoD2bEShX_vW2wQ&usqp=CAU' -> logo
ui <-
fluidPage(
titlePanel("Thomas More University COVID-19 Dashboard"),
tableOutput('covTable'),
textOutput("text1"),
mainPanel(plotlyOutput("covTrend"),
"",
textOutput('text2'))
)
server <- function(input, output, session) {
output$text1 <- renderText(
'https://www.thomasmore.edu/covid-19/healthy-at-thomas-more-plan/covid-19-dashboard/' %>%
read_html %>%
html_nodes("p") %>%
html_text %>%
.[grepl("[*]", .)]
)
output$text2 <- renderText(
'Data from: https://www.thomasmore.edu/covid-19/healthy-at-thomas-more-plan/covid-19-dashboard/'
)
output$covTable <- renderTable(dat[[1]], align = 'c')
output$covTrend <- renderPlotly(
ggplotly(
dat[[2]] %>%
mutate_at(vars(`Date Reported`, `Resolved Date`), ~ gsub("[.]", "", .)) %>%
mutate_at(
vars(`Date Reported`, `Resolved Date`),
~ gsub("Sept", "Sep", .)
) %>%
mutate_at(
vars(`Date Reported`, `Resolved Date`),
~ as.Date(., "%B %d, %Y")
) %>%
arrange(`Date Reported`) %>%
mutate(
`Date Last on Campus` = as.Date(`Date Last on Campus`, "%m/%d/%Y"),
count = 1,
`Cumulative Count of Cases` = cumsum(count),
count = NULL,
`Campus Impact` = gsub("[.] ", ".\n", `Campus Impact`)
) %>%
ggplot(aes(x = `Date Reported`, y = `Cumulative Count of Cases`)) +
# geom_smooth(method = 'loess', formula = 'y ~ x') +
geom_line() +
geom_point(aes(color = Constituent, text = `Campus Impact`), size = 3) +
geom_vline(xintercept = as.Date("2020-08-17"), size = 1) +
geom_text(aes(
x = as.Date("2020-08-10"),
y = 13,
label = "Fall Classes Start"
)) +
geom_text(aes(
x = as.Date("2020-08-30"),
y = 13,
label = "Labor Day Weekend"
)) +
geom_vline(xintercept = as.Date("2020-09-7"), size = 1) +
scale_color_manual(values = c("#003594", "#B2B4B2")) +
# scale_y_continuous(limits = c(0, 20)) +
theme_light() +
labs(
title = "Thomas More University COVID-19 Trends",
subtitle = format(Sys.Date(), "%B %d, %Y"),
caption = "Data from https://www.thomasmore.edu/covid-19/healthy-at-thomas-more-plan/covid-19-dashboard/"
)
)
)
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment