Newer
Older
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
### Coords information changes
# coords <- coords %>%
# select(name, id_sivep, id_cdps, X, Y) %>%
# mutate(id_sivep = as.character(id_sivep)) %>%
# mutate(id_cdps = as.character(id_cdps)) %>%
# mutate(id_sivep = str_replace_all(id_sivep, "[\r\n]" , "")) %>%
# mutate(id_cdps = str_replace_all(id_cdps, "[\r\n]" , "")) %>%
# mutate(X = as.numeric(as.character(X)), Y = as.numeric(as.character(Y))) %>%
# mutate(name = as.character(name)) %>%
# mutate(id = if_else(is.na(id_sivep), id_cdps, id_sivep)) %>%
# mutate(y_coordinate = Y, x_coordinate = X) %>%
# select(id, name, x_coordinate, y_coordinate)
### Map tab
output$map <- renderLeaflet({
# First load populate
date1 <- as.Date("2007-01-01")
date2 <- as.Date(today())
df <- JSON_cons_har %>%
filter(consultation_date >= date1 & consultation_date <= date2) %>%
select(residence_place, source) %>%
group_by(residence_place, source) %>%
dplyr::summarise(count=n()) %>%
inner_join(coords, by = c("residence_place" = "id")) %>%
mutate(id = residence_place)
pal <- colorFactor(c("red","blue"), df$source)
leaflet() %>%
addTiles(options = providerTileOptions(maxZoom = 10)) %>%
setView(lng = -51.548, lat = 3.938, zoom = 9) %>%
addCircleMarkers(
layerId = ~id,
data = df[which(df$source == "FR-GF"),],
lat = ~y_coordinate,
lng = ~x_coordinate,
radius = ~log(count+1)*1.5,
color = ~pal(source),
stroke = FALSE, fillOpacity = 0.5,
label = ~paste0(as.character(name), " (", source, ")", ": ", count)
) %>%
addCircleMarkers(
layerId = ~id,
data = df[which(df$source == "BR"),],
lat = ~y_coordinate,
lng = ~x_coordinate,
radius = ~log(count+1)*1.5,
color = ~pal(source),
stroke = FALSE, fillOpacity = 0.5,
label = ~paste0(as.character(name), " (", source, ")", ": ", count)
) %>%
addLegend("bottomleft", pal = pal, values = df$source, layerId = "mapLegend")
})
output$MAPmissing <- renderText("")
# Interactive populate
observe({
# Input requirements
req(input$MAPdates)
req(input$MAPtype)
date1 <- as.Date(paste0(input$MAPdates[1],"-01-01"))
date2 <- as.Date(paste0(input$MAPdates[2],"-12-31"))
map_type <- input$MAPtype
if(map_type == "residence_area"){
df <- JSON_cons_har %>%
filter(consultation_date >= date1 & consultation_date <= date2) %>%
select(residence_place, source) %>%
group_by(residence_place, source) %>%
dplyr::summarise(count=n()) %>%
inner_join(coords, by = c("residence_place" = "id")) %>%
mutate(id = residence_place)
missing_total <- JSON_cons_har %>%
filter(consultation_date >= date1 & consultation_date <= date2) %>%
nrow()
missing_per <- round((sum(df$count)/missing_total)*100, 2)
missing_n <- sum(df$count)
} else if(map_type == "infection_place"){
df <- JSON_cons_har %>%
filter(consultation_date >= date1 & consultation_date <= date2) %>%
select(infection_place, source) %>%
group_by(infection_place, source) %>%
dplyr::summarise(count=n()) %>%
inner_join(coords, by = c("infection_place" = "id")) %>%
mutate(id = infection_place)
missing_total <- JSON_cons_har %>%
filter(consultation_date >= date1 & consultation_date <= date2) %>%
nrow()
missing_per <- round((sum(df$count)/missing_total)*100, 2)
missing_n <- sum(df$count)
}
# Map
pal <- colorFactor(c("red","blue"), df$source)
leafletProxy("map") %>%
clearMarkers() %>%
addCircleMarkers(
layerId = ~id,
data = df,
lat = ~y_coordinate,
lng = ~x_coordinate,
radius = ~log(count+1)*1.5,
color = ~pal(df$source),
stroke = FALSE, fillOpacity = 0.5,
label = ~paste0(as.character(name), " (", source, ")", ": ", count)
) %>% addLegend("bottomleft", pal = pal, values = df$source, layerId = "mapLegend")
#output$MAPmissing <- renderText(paste0("De ", missing_total, "registros, foram localizados no mapa ", missing_n, " (", missing_per, "%)."))
output$MAPmissing <- renderText(paste0(tr("missing_1"), " ", missing_total," ", tr("missing_2"), ", ", missing_n, " (", missing_per, "%) ", tr("missing_3"), "."))
})