forked from green-striped-gecko/covid_canberra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.Rmd
481 lines (360 loc) · 14.3 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
---
title: "Home"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
source_code: embed
includes:
before_body: _header.html
after_body: _footer.html
background_image: ".//assets/img/mod_petral.jpg"
#runtime: shiny
# params:
# lup: "unknown"
editor_options:
chunk_output_type: console
---
<!-- # ```{r, echo=FALSE} -->
<!-- # htmltools::img(src = knitr::image_uri(file.path(R.home("doc"), "html", "logo.jpg")), -->
<!-- # alt = 'logo', -->
<!-- # style = 'position:absolute; top:0; right:0; padding:10px;') -->
<!-- # ``` -->
<!-- body { -->
<!-- background-image: url('https://linesteppers.com/tutorials/RMarkdown/img/BannerImage_TreeBlossoms_4470x3024.jpg'); -->
<!-- background-repeat: no-repeat; -->
<!-- background-size: 100%; -->
<!-- } -->
<!-- div { -->
<!-- background-color: rgba(255, 255, 255, 0.35) /* 35% opaque white */; -->
<!-- padding: 0.25em; -->
<!-- } -->
```{r setup, include=TRUE}
library(tidyverse)
library(ggmap)
library(leaflet)
library(plotly)
library(flexdashboard)
library(DT)
library(rgdal)
library(crosstalk)
# devtools::install_github("r-spatial/leafem")
# library(leafem)
#latest dataset
tab3 <- read.csv("https://raw.githubusercontent.com/green-striped-gecko/covid_canberra/main/data/last.csv")
# Aggregate method
cols <- c( "red", "yellow","blue")
addBuses <- FALSE
tab3$Contact <- factor(tab3$Contact,levels=c( "Close" , "Casual", "Monitor") )
cc <- as.numeric( tab3$Contact)
ncols <- c("black","cyan")
nn <- as.numeric(factor(tab3$Status))
nn2 <- ifelse(nn==1,nn, 3)
tab3$Date <- substr(tab3$Date,1,10) #ditch day of the week
labs <- paste(tab3$Contact, tab3$Status,tab3$Exposure.Location, tab3$Street, tab3$Suburb, tab3$Date,tab3$Arrival.Time, tab3$Departure.Time, tab3$doubles, sep="<br/>")
###############################################
##plot the map
df_shared <- crosstalk::SharedData$new(tab3[,c(1,8,2:7)])
m <- leaflet(df_shared) %>% addTiles()
if (addBuses) {
#read from shape file
busses <- readOGR(dsn = "./bus", layer = "geo_export_69c76e06-1d3f-4619-be3b-b4e5789be8ca", verbose = FALSE)
#search all bus lines that are mentioned
bindex <- grep("Bus Route", tab3$Exposure.Location)
buslanes <- tab3$Exposure.Location[bindex]
busnumbers <- gsub("Bus Route ([0-9,A-Z]+) Transport.*","\\1", buslanes)
blineindex <- which(busses$short_name %in% busnumbers)
blabs <- paste(paste0("Bus route: ", busses$short_name[blineindex]),"<strong> For bus stops and ","exposure times, please"," search the table." , sep="<br/>")
bb <- (busses[blineindex,])
coo <- coordinates(bb)
bcols <- colorRampPalette(c("purple", "green"))( length(coo))
for (ib in 1:length(coo))
{
cood <- data.frame(coo[[ib]])
m <- m %>% addPolylines(lng=cood[,1], lat=cood[,2], color = bcols[ib], weight = 5, opacity = 0.7, popup = blabs[ib])
}
}
m <- m %>% addCircleMarkers(lat=tab3$lat, lng=tab3$lon,popup = labs, weight=nn2, fillColor = cols[cc],color=ncols[nn], opacity =0.8, radius = 5 , fillOpacity = 0.8)
# , clusterOptions =markerClusterOptions(spiderfyDistanceMultiplier=1.5,
# iconCreateFunction=JS("function (cluster) {
#
# var childCount = cluster.getChildCount();
#
# if (childCount < 100) {
# c = 'rgba(64, 64, 64, 0.5);'
# } else if (childCount < 1000) {
# c = 'rgba(64, 64, 64, 0.5);'
# } else {
# c = 'rgba(64, 64, 64, 0.5);'
# }
# return new L.DivIcon({ html: '<div style=\"background-color:'+c+'\"><span>' + childCount + '</span></div>', className: 'marker-cluster', iconSize: new L.Point(40, 40) });
# }")) #)
m <- m %>% addLegend("bottomright", labels = levels(tab3$Contact), colors = cols, opacity = 0.8)
####################################################
### add bus lines mentioned
# m + addLogo("./assets/img/Capture1.PNG", alpha = 1, src = c("remote", "local"), url,
# position = c("topleft", "topright", "bottomleft", "bottomright"),
# offset.x = 50, offset.y = 13, width = 60, height = 60)
#
```
Current {data-orientation=columns}
=====================================
<style>
.crosstalk-input-checkboxgroup{
color: blue;
font-size: 12px;
}
.navbar {
background-color:grey;
hover-color:yellow;
}
</style>
Inputs {.sidebar}
-----------------------------------------------------------------------
### Information
<sup>Disclaimer: This map shows the covid exposure locations in the ACT and is an **unofficial website** based on [official sources](https://www.covid19.act.gov.au/act-status-and-response/act-covid-19-exposure-locations). So if in doubt, refer to the [offical website](https://www.covid19.act.gov.au/act-status-and-response/act-covid-19-exposure-locations), which has now also an [**official map**](https://www.covid19.act.gov.au/act-status-and-response/act-covid-19-exposure-locations/map#Map-of-ACT-exposure-locations) included. Supported by Volunteers from the University of Canberra. Contacts: Bernd Gruber [[email protected]] & Anthony Davidson [[email protected]]</sup>
<br>
<br>
### Filter
```{r}
bscols(
filter_checkbox(
id = "contact",
label = "Contact",
sharedData = df_shared,
group = ~Contact,
columns = 1
))
bscols(
filter_checkbox(
id = "status",
label = "Status",
sharedData = df_shared,
group = ~Status,
columns = 1
))
bscols( filter_select(id="dates", label="Date",sharedData = df_shared, group=~Date))
bscols( filter_select(id="suburb", label="Suburb",sharedData = df_shared, group=~Suburb))
```
```{r}
```
Column {data-width=500}{.tabset}
------------------------------------------------------------
### Map of Exposure sites and exposed bus routes
```{r}
m %>%
addProviderTiles("Stamen.TonerLite")
# %>%
# addPolygons(
# # fill
# fillColor = ~pal(water_km2),
# fillOpacity = 0.7,
# # line
# dashArray = "3",
# weight = 2,
# color = "white",
# opacity = 1,
# # interaction
# highlight = highlightOptions(
# weight = 5,
# color = "#666",
# dashArray = "",
# fillOpacity = 0.7,
# bringToFront = TRUE))
```
### New Cases today
```{r eval = TRUE}
##current dataset..
#import now
library(tidyverse)
library(ggmap)
library(leaflet)
library(plotly)
library(flexdashboard)
library(DT)
library(rgdal)
library(crosstalk)
library(absmapsdata)
library(sf)
############very ugly function But should work.....
##ARD sep2021
last_five_days_new <- function(dataList){
#no new sites test
tab3 <- read.csv(dataList)
cols <- c( "red", "yellow","blue")
tab3$Contact <- factor(tab3$Contact,levels=c( "Close" , "Casual", "Monitor") )
cc <- as.numeric( tab3$Contact)
ncols <- c("black","cyan")
nn <- as.numeric(factor(tab3$Status))
nn2 <- ifelse(nn==1,nn, 3)
# glimpse(tab3)
tab3$Date <- substr(tab3$Date,1,10) #ditch day of the week
labs <- paste(tab3$Contact, tab3$Status,tab3$Exposure.Location, tab3$Street, tab3$Suburb, tab3$Date,tab3$Arrival.Time, tab3$Departure.Time, tab3$doubles, sep="<br/>")
dataJoin <- absmapsdata::sa12016 %>%
filter(gcc_name_2016 == "Australian Capital Territory") %>%
mutate(Suburb = sa2_name_2016) %>%
left_join(tab3, by = c("Suburb")) %>%
select(Suburb, lat, lon, Exposure.Location, geometry,Status, Contact) %>%
na.omit() %>%
mutate(Status = ifelse(Status == "New", "New", "Previous")) %>%
st_as_sf
glimpse(dataJoin)
# <NA> and NA
# remove_missing(vars = c("Exposure.Location"))%>% # let's just look Melbourne
plot1 <- ggplot(dataJoin,aes(y=lat, x=lon)) +
ggspatial::annotation_map_tile() +
geom_sf(aes(geometry = geometry, fill = Status),
col = c("red"),
lty = 1, alpha =0.1)+
scale_fill_manual(values = c("red", "yellow","blue")) +
geom_point(data = dataJoin, aes(y=lat, x=lon, fill = Status,alpha = 0.7), size = 2 ) #+
# scale_fill_manual(values = c("red", "yellow","blue","black", "white")) +
# scale_color_manual(values = c("red", "yellow","blue","black", "white"))
return(plot1)
} #function end
#lapply
p1 <- last_five_days_new(dataList = "./data/last.csv")
# dataList = "./data/allfiles/September/table_01_Sep_2021_136pm.csv"
# lapply(dataList, last_five_days_new)
p1
```
Column {data-width=350}
------------------------------------------------------------
### Table of new cases
```{r}
# bscols(
# filter_checkbox(
# id = "contact",
# label = "",
# sharedData = df_shared,
# group = ~Contact,
# inline=TRUE
# ))
#bscols( filter_select(id="dates", label="Date",sharedData = df_shared, group=~Date))
dtt <-DT::datatable(df_shared,
caption = 'Search for entries, (shift)click to select, this highlights the locations in the map.',selection = "multiple", rownames = FALSE,
extensions = c("Buttons", "Select", "Responsive"), options = list(autoHideNavigation=FALSE, pageLength=50,
dom = 'Bfrtip',
select = TRUE,
buttons = list(
"copy",
list(
extend = "selectNone",
text = "Clear"
)
),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'font-size': '50%'});",
"}"))) %>% DT::formatStyle(columns = 1:8, fontSize='70%')
dtt
```
Cases, contacts and hotspots {data-orientation=columns}
=====================================
<!-- This data is collected using code that accesses twitter, act govt site, nsw govt site, vic govt site...? -->
<sup>Disclaimer: This work This map shows the covid exposure locations in the ACT and is an **unofficial website** based on [official sources](https://www.covid19.act.gov.au/act-status-and-response/act-covid-19-exposure-locations). So if in doubt, refer to the [offical website](https://www.covid19.act.gov.au/act-status-and-response/act-covid-19-exposure-locations), which has now also an [**official map**](https://www.covid19.act.gov.au/act-status-and-response/act-covid-19-exposure-locations/map#Map-of-ACT-exposure-locations) included. Supported by Volunteers from the University of Canberra. Contacts: Bernd Gruber [[email protected]] & Anthony Davidson [[email protected]]</sup>
Column {data-width=400}{.tabset}
------------------------------------------------------------
```{r eval = TRUE}
# source("R/plotly_source_script.R")
source("R/plotly_source_script.R")
```
### Map of Exposure sites
```{r}
# source("R/plotly_source_script.R")
library(plotly)
library(ggplotlyExtra)
library(leaflet)
leaflet(plotsumms) %>% addTiles() %>%
addCircleMarkers(lat=plotsumms$lat,
lng=plotsumms$lon,
weight = 0.2,
radius = log(plotsumms$contactcount)*20,
popup = paste0(" COUNT:", plotsumms$contactcount),
fillOpacity = 0.1,
# color = plotsumms$colsN,
color = "grey50"
) %>%
addCircles(lat=tab4$lat,lng=tab4$lon,
popup = paste0(plotsumms$Exposure.Location," ", plotsumms$Date),
color = plotsumms$colsN,
stroke = TRUE,
fill = rep("black", length(plotsumms$colsN))) %>%
addLegend("bottomright",
labels = levels(plotsumms$Contact),
colors = levels(plotsumms$colsN),
opacity = 0.8)
```
This website tracks COVID-19 data and mobility information for the ACT and Canberra using code and data developed in the open source community. This information is only a guide. Please refer to official reports and press releases from government certified resources.
### Yesterdays case numbers
```{r eval = TRUE}
##current dataset..
#import now
library(tidyverse)
library(ggmap)
library(leaflet)
library(plotly)
library(flexdashboard)
library(DT)
library(rgdal)
library(crosstalk)
library(absmapsdata)
library(sf)
############very ugly function But should work.....
#dataList is a list...
##ARD sep2021
last_five_days_new <- function(dataList){
#no new sites test
tab3 <- read.csv(dataList)
cols <- c( "red", "yellow","blue")
tab3$Contact <- factor(tab3$Contact,levels=c( "Close" , "Casual", "Monitor") )
cc <- as.numeric( tab3$Contact)
ncols <- c("black","cyan")
nn <- as.numeric(factor(tab3$Status))
nn2 <- ifelse(nn==1,nn, 3)
# glimpse(tab3)
tab3$Date <- substr(tab3$Date,1,10) #ditch day of the week
labs <- paste(tab3$Contact, tab3$Status,tab3$Exposure.Location, tab3$Street, tab3$Suburb, tab3$Date,tab3$Arrival.Time, tab3$Departure.Time, tab3$doubles, sep="<br/>")
dataJoin <- absmapsdata::sa12016 %>%
filter(gcc_name_2016 == "Australian Capital Territory") %>%
mutate(Suburb = sa2_name_2016) %>%
left_join(tab3, by = c("Suburb")) %>%
select(Suburb, lat, lon, Exposure.Location, geometry,Status, Contact) %>%
na.omit() %>%
mutate(Status = ifelse(Status == "New", "New", "Previous")) %>%
st_as_sf
glimpse(dataJoin)
# <NA> and NA
# remove_missing(vars = c("Exposure.Location"))%>% # let's just look Melbourne
plot1 <- ggplot(dataJoin,aes(y=lat, x=lon)) +
ggspatial::annotation_map_tile() +
geom_sf(aes(geometry = geometry, fill = Status),
col = c("red"),
lty = 1, alpha =0.5)+
scale_fill_manual(values = c("red", "yellow","blue")) +
geom_point(data = dataJoin, aes(y=lat, x=lon), size = 4, alpha = 0.3) #+
# scale_fill_manual(values = c("red", "yellow","blue","black", "white")) +
# scale_color_manual(values = c("red", "yellow","blue","black", "white"))
return(plot1)
} #function end
#lapply
# p1 <- last_five_days_new(dataList = "./data/allfiles/September/table_01_Sep_2021_136pm.csv")
# dataList = "./data/allfiles/September/table_01_Sep_2021_136pm.csv"
# lapply(dataList, last_five_days_new)
p1
```
### TODAY
```{r eval = FALSE}
#lapply
p1 <- last_five_days_new(dataList = "./data/allfiles/September/table_02_Sep_2021_704pm.csv")
# dataList = "./data/allfiles/September/table_01_Sep_2021_136pm.csv"
# lapply(dataList, last_five_days_new)
p1
```
```{r child = "about.Rmd"}
```
Previous draft {data-orientation=columns}
=====================================
```{r child = "Covid_Exposure_ACT.rmd"}
```