Skip to content

Commit

Permalink
Adding map tab
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleKendall committed Jan 1, 2021
1 parent 4e49df3 commit fba6017
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 3 deletions.
Binary file added data/engwales.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions data/engwales.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]]
Binary file added data/engwales.shp
Binary file not shown.
Binary file added data/engwales.shx
Binary file not shown.
Binary file modified data/latest_df.for.plotting.incidence.ltlas.RData
Binary file not shown.
Binary file modified data/latest_projected.cases.ltlas.RData
Binary file not shown.
3 changes: 2 additions & 1 deletion data/population_by_region.csv
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,5 @@ Mid Ulster,Local Government District,148528
"Newry, Mourne and Down",Local Government District,181368
Aylesbury Vale,Not sure,199448
South Bucks,Not sure,70043
Wycombe,Not sure,174641
Wycombe,Not sure,174641
Chiltern,Not sure,95927
6 changes: 6 additions & 0 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ library(data.table) # for cases by age
library(stringr) # for cases by age
library(stringi) # for cases by age
library(viridis)
library(leaflet) # for maps
library(sf) # for maps
library(adegenet) # for colouring maps
# library(httr) # for accessing latest data; needed this when updates were done within the app but don't need it whilst running "prepping_the_data.R" manually
# options(shiny.trace = TRUE)
# options(shiny.trace = FALSE)
Expand All @@ -21,6 +24,9 @@ bs <- 24 # base font size for plots
source("prep/daily_tracker_setup.R") # load data and plotting scripts for daily tracker tab
source("prep/cases_by_age_setup.R") # get plotting script for cases by age tab

engwalesmap <- st_read("data/engwales.shp") # load shapefile for maps
mapcounter <- 1

# load synthetic control analysis
for (i in 1:8) {
tmp <- read.csv(glue("data/sc_dataset_scenario_{i}.csv"))
Expand Down
4 changes: 3 additions & 1 deletion markdown/about.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ The tabs "March-June Pillar 1 tracker" and "March-June Pillar 1 synthetic contro

The "Daily tracker" tab which is updated daily builds upon our published analysis, using a shorter waiting time between infection and swab date to reflect shorter times to Pillar 2 testing.

The "Map tracker" tab presents the same results as the "Daily tracker" but visualised using maps. We thank Will Probert for providing shapefiles and code towards this.

The "Cases by age" tab presents an analysis developed by Robert Hinch and Michelle Kendall and is also updated daily.

The source code is available on [GitHub](https://github.com/BDI-pathogens/LocalCovidTracker).
Please let us know of any issues or requests via the [Issues](https://github.com/BDI-pathogens/LocalCovidTracker/issues) page.

<br>

[1] Michelle Kendall, Luke Milsom, Lucie Abeler-Dörner, Chris Wymant, Luca Ferretti, Mark Briers, Chris Holmes, David Bonsall, Johannes Abeler, Christophe Fraser. <a href="http://www.thelancet.com/journals/landig/article/PIIS2589-7500(20)30241-7/fulltext" target="_blank"> Epidemiological changes on the Isle of Wight after the launch of the NHS Test and Trace programme: a preliminary analysis</a>, <i>The Lancet Digital Health</i>, published online October 14, 2020.
[1] Michelle Kendall, Luke Milsom, Lucie Abeler-Dörner, Chris Wymant, Luca Ferretti, Mark Briers, Chris Holmes, David Bonsall, Johannes Abeler, Christophe Fraser. <a href="http://www.thelancet.com/journals/landig/article/PIIS2589-7500(20)30241-7/fulltext" target="_blank"> Epidemiological changes on the Isle of Wight after the launch of the NHS Test and Trace programme: a preliminary analysis</a>, <i>The Lancet Digital Health</i>, Volume 2, Issue 12, E658-E666, December 01, 2020.



Expand Down
4 changes: 3 additions & 1 deletion markdown/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ The tabs "March-June Pillar 1 tracker" and "March-June Pillar 1 synthetic contro

The "Daily tracker" tab which is updated daily builds upon our published analysis, using a shorter waiting time between infection and swab date to reflect shorter times to Pillar 2 testing.

The "Map tracker" tab presents the same results as the "Daily tracker" but visualised using maps. We thank Will Probert for providing shapefiles and code towards this.

The "Cases by age" tab presents an analysis developed by Robert Hinch and Michelle Kendall and is also updated daily.

The source code is available on [GitHub](https://github.com/BDI-pathogens/LocalCovidTracker).
Please let us know of any issues or requests via the [Issues](https://github.com/BDI-pathogens/LocalCovidTracker/issues) page.

<br>

[1] Michelle Kendall, Luke Milsom, Lucie Abeler-Dörner, Chris Wymant, Luca Ferretti, Mark Briers, Chris Holmes, David Bonsall, Johannes Abeler, Christophe Fraser. <a href="http://www.thelancet.com/journals/landig/article/PIIS2589-7500(20)30241-7/fulltext" target="_blank"> Epidemiological changes on the Isle of Wight after the launch of the NHS Test and Trace programme: a preliminary analysis</a>, <i>The Lancet Digital Health</i>, published online October 14, 2020.
[1] Michelle Kendall, Luke Milsom, Lucie Abeler-Dörner, Chris Wymant, Luca Ferretti, Mark Briers, Chris Holmes, David Bonsall, Johannes Abeler, Christophe Fraser. <a href="http://www.thelancet.com/journals/landig/article/PIIS2589-7500(20)30241-7/fulltext" target="_blank"> Epidemiological changes on the Isle of Wight after the launch of the NHS Test and Trace programme: a preliminary analysis</a>, <i>The Lancet Digital Health</i>, Volume 2, Issue 12, E658-E666, December 01, 2020.



Expand Down
253 changes: 253 additions & 0 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,252 @@ server <- function(input, output, session) {
)
})

### MAPS

getDateMaps <- reactive({
as.Date(input$date.slider.maps, format="%d %b %y")
})

output$mapDate <- renderUI({
nice.date <- format(getDateMaps(), format="%d %B %Y")
HTML(glue("<h2><b>{nice.date}</b></h2>"))
})

output$NowcastMap <- renderLeaflet({
this.date.nowcast <- projected.cases.ltlas %>% filter(Dates == last.date - 31 - R.trim)
this.date.nowcast$lad19cd <- this.date.nowcast$AreaCode
this.date.nowcast$fill <- num2col(this.date.nowcast$scaled_per_capita, col.pal=colorRampPalette(c('#fff5f0','#fee0d2','#fcbba1','#fc9272','#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d')), x.max=60)

# combine shape and epi data
# using "right_join" removes the places for which we don't have data (Scotland etc.)
engwales <- right_join(engwalesmap, subset(this.date.nowcast, select = c("scaled_per_capita","lad19cd","fill")), by = "lad19cd")

engwales <- engwales %>% st_transform('+proj=longlat +datum=WGS84') # convert the shapefile coordinates into longitudes and latitudes, ready for the leaflet package

NowcastHoverInfo <- sprintf(
"<strong>%s</strong><br/>Projected %g new<br/>infections per 100,000<br/>in the near future",
engwales$lad19nm, round(engwales$scaled_per_capita,1)
) %>% lapply(htmltools::HTML)

leaflet(engwales) %>%
addPolygons(layerId = paste0("nowcast.",mapcounter,".",1:337),
fillColor = ~fill,
weight = 1,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 1,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = NowcastHoverInfo,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend("topright",
colors = colorRampPalette(c('#fff5f0','#fee0d2','#fcbba1','#fc9272','#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d'))(7),
labels = c(seq(0,50,by=10),"60+"),
title = "per 100,000")

})

output$InfectionsMap <- renderLeaflet({
this.date.inf <- df.for.plotting.incidence.ltlas %>% filter(Dates == last.date - 31 - R.trim)
this.date.inf$lad19cd <- this.date.inf$AreaCode
this.date.inf$fill <- num2col(this.date.inf$scaled_per_capita, col.pal=colorRampPalette(c('#fff5f0','#fee0d2','#fcbba1','#fc9272','#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d')), x.max=60)

# combine shape and epi data
# using "right_join" removes the places for which we don't have data (Scotland etc.)
engwales <- right_join(engwalesmap, subset(this.date.inf, select = c("scaled_per_capita","lad19cd", "fill")), by = "lad19cd")

engwales <- engwales %>% st_transform('+proj=longlat +datum=WGS84') # convert the shapefile coordinates into longitudes and latitudes, ready for the leaflet package

InfHoverInfo <- sprintf(
"<strong>%s</strong><br/>%g new infections per 100,000",
engwales$lad19nm, round(engwales$scaled_per_capita,1)
) %>% lapply(htmltools::HTML)

leaflet(engwales) %>%
addPolygons(layerId = paste0("infections.",mapcounter,".",1:337),
fillColor = ~fill,
weight = 1,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 1,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = InfHoverInfo,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend("topright",
colors = colorRampPalette(c('#fff5f0','#fee0d2','#fcbba1','#fc9272','#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d'))(7),
labels = c(seq(0,50,by=10),"60+"),
title = "per 100,000")
})

output$RMap <- renderLeaflet({
this.date.R <- df.for.plotting.R.ltlas %>% filter(Dates == last.date - 31 - R.trim)
this.date.R$lad19cd <- this.date.R$AreaCode
this.date.R$fill <- num2col(this.date.R$R, col.pal=colorRampPalette(c('#313695','#4575b4','#74add1','#abd9e9','#e0f3f8','#ffffbf','#fee090','#fdae61','#f46d43','#d73027','#a50026')), x.min=0, x.max=2)

# combine shape and epi data
# using "right_join" removes the places for which we don't have data (Scotland etc.)
engwales <- right_join(engwalesmap, subset(this.date.R, select = c("R", "lad19cd", "fill")), by = "lad19cd")

engwales <- engwales %>% st_transform('+proj=longlat +datum=WGS84') # convert the shapefile coordinates into longitudes and latitudes, ready for the leaflet package

RHoverInfo <- sprintf(
"<strong>%s</strong><br/>R = %g",
engwales$lad19nm, round(engwales$R,2)
) %>% lapply(htmltools::HTML)

leaflet(engwales) %>%
addPolygons(layerId = paste0("R.",mapcounter,".",1:337),
fillColor = ~fill,
weight = 1,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 1,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = RHoverInfo,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend("topright",
colors = colorRampPalette(c('#313695','#4575b4','#74add1','#abd9e9','#e0f3f8','#ffffbf','#fee090','#fdae61','#f46d43','#d73027','#a50026'))(5),
labels = c("0.0","0.5","1.0","1.5","2.0+"),
title = "R")

})

observeEvent(input$date.slider.maps, {
this.date <- getDateMaps()

this.date.nowcast <- projected.cases.ltlas %>% filter(Dates == this.date)
this.date.nowcast$lad19cd <- this.date.nowcast$AreaCode
this.date.nowcast$fill <- num2col(this.date.nowcast$scaled_per_capita, col.pal=colorRampPalette(c('#fff5f0','#fee0d2','#fcbba1','#fc9272','#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d')), x.max=60)

this.date.inf <- df.for.plotting.incidence.ltlas %>% filter(Dates == this.date)
this.date.inf$lad19cd <- this.date.inf$AreaCode
this.date.inf$fill <- num2col(this.date.inf$scaled_per_capita, col.pal=colorRampPalette(c('#fff5f0','#fee0d2','#fcbba1','#fc9272','#fb6a4a','#ef3b2c','#cb181d','#a50f15','#67000d')), x.max=60)

this.date.R <- df.for.plotting.R.ltlas %>% filter(Dates == this.date)
this.date.R$lad19cd <- this.date.R$AreaCode
this.date.R$fill <- num2col(this.date.R$R, col.pal=colorRampPalette(c('#313695','#4575b4','#74add1','#abd9e9','#e0f3f8','#ffffbf','#fee090','#fdae61','#f46d43','#d73027','#a50026')), x.min=0, x.max=2)

# combine shape and epi data
# using "right_join" removes the places for which we don't have data (Scotland etc.)
this.date.nowcast <- right_join(engwalesmap, subset(this.date.nowcast, select = c("scaled_per_capita","lad19cd","fill")), by = "lad19cd")
this.date.nowcast <- this.date.nowcast %>% st_transform('+proj=longlat +datum=WGS84') # convert the shapefile coordinates into longitudes and latitudes, ready for the leaflet package

this.date.inf <- right_join(engwalesmap, subset(this.date.inf, select = c("scaled_per_capita","lad19cd", "fill")), by = "lad19cd")
this.date.inf <- this.date.inf %>% st_transform('+proj=longlat +datum=WGS84') # convert the shapefile coordinates into longitudes and latitudes, ready for the leaflet package

this.date.R <- right_join(engwalesmap, subset(this.date.R, select = c("R", "lad19cd", "fill")), by = "lad19cd")
this.date.R <- this.date.R %>% st_transform('+proj=longlat +datum=WGS84') # convert the shapefile coordinates into longitudes and latitudes, ready for the leaflet package

NowcastHoverInfo <- sprintf(
"<strong>%s</strong><br/>Projected %g new<br/>infections per 100,000<br/>in the near future",
this.date.nowcast$lad19nm, round(this.date.nowcast$scaled_per_capita,1)
) %>% lapply(htmltools::HTML)

InfHoverInfo <- sprintf(
"<strong>%s</strong><br/>%g new infections per 100,000",
this.date.inf$lad19nm, round(this.date.inf$scaled_per_capita,1)
) %>% lapply(htmltools::HTML)

RHoverInfo <- sprintf(
"<strong>%s</strong><br/>R = %g",
this.date.R$lad19nm, round(this.date.R$R,2)
) %>% lapply(htmltools::HTML)

leafletProxy("NowcastMap", data=this.date.nowcast) %>%
addPolygons(layerId = paste0("nowcast.",mapcounter+1,".",1:337), # assigning layerIds is supposed to mean that the previous ones get deleted (otherwise there's a big slow-down as more dates are viewed)
fillColor = ~fill,
weight = 1,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 1,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = NowcastHoverInfo,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
removeShape(layerId = paste0("nowcast.",mapcounter,".",1:337)) # remove the _underneath_ layer so that we don't get jumpiness or slowdown

leafletProxy("InfectionsMap", data=this.date.inf) %>%
addPolygons(layerId = paste0("infections.",mapcounter+1,".",1:337),
fillColor = ~fill,
weight = 1,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 1,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = InfHoverInfo,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
removeShape(layerId = paste0("infections.",mapcounter,".",1:337))

leafletProxy("RMap", data=this.date.R) %>%
addPolygons(layerId = paste0("R.",mapcounter+1,".",1:337),
fillColor = ~fill,
weight = 1,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 1,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = RHoverInfo,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
removeShape(layerId = paste0("R.",mapcounter,".",1:337))

mapcounter <- mapcounter + 1
})

# output$MapTitle <- renderUI({
# h3(format(getDateMaps(), "%d %B %Y"))
# })

### Cases by age

Expand Down Expand Up @@ -985,6 +1231,13 @@ server <- function(input, output, session) {
HTML(glue("<h5>Last updated {last.datestamp} <br>using data up to {last.date.of.data}.</h5>"))
})


output$updatedInfoMaps <- renderUI({
last.datestamp <- getLastDatestamp()
last.date.of.data <- getLastDateOfData()
HTML(glue("<h5>Last updated {last.datestamp} <br>using data up to {last.date.of.data}.</h5>"))
})

output$updatedInfoAges <- renderUI({
last.datestamp <- getLastDatestamp()
last.date.of.data <- getLastDateOfData()
Expand Down
Loading

0 comments on commit fba6017

Please sign in to comment.