-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
105 lines (97 loc) · 4.31 KB
/
server.R
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
# server
library(shiny)
library(dplyr)
library(sf)
library(leaflet)
library(leaflet.extras2)
# server logic
function(input, output, session) {
hintjs(session)
output$enabling_map <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addMapPane('layer1', zIndex = 410) %>%
addMapPane('layer2', zIndex = 460) %>%
addCircleMarkers(group = "Case study Theories of Change",
data = toc_dat,
color = ~pal2(Ecosystem),
weight = 1,
opacity = 1,
fillOpacity = 0.8,
radius = 5,
popup= pop_up,
options = pathOptions(pane = "layer2")) %>%
addLegend("bottomright",
#data = toc_dat,
colors =rgb(t(col2rgb(palset)) / 255),
#values = ~Ecosystem,
labels = c('Enabling profile 1', 'Enabling profile 2', 'Enabling profile 3',
'Enabling profile 4', 'Enabling profile 5', 'Enabling profile 6'),
title = "Enabling profiles",
opacity = 1) %>%
addLegend("bottomright",
#data = toc_dat,
colors =rgb(t(col2rgb(c('darkgoldenrod1', 'midnightblue'))) / 255),
#values = ~Ecosystem,
labels = c('Mangroves', 'Seagrass'),
title = "Case-study Theories of Change",
opacity = 1, group = "Case study Theories of Change") %>%
addLayersControl(
overlayGroups = c("Case study Theories of Change"),
options = layersControlOptions(collapsed = FALSE)) #%>%
#hideGroup("Case study Theories of Change")
}) # end render leaflet
# updated map based on user inputs
observe({
if(input$var == 'Globe'){
bounds <- unname(st_bbox(world.clust))
leafletProxy('enabling_map') %>%
addSpinner() %>%
startSpinner(options = list("lines" = 7, "length" = 20)) %>%
flyToBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
clearGroup(c('basepoly', 'countrypoly', 'profilepoly')) %>%
addPolygons(
group = 'basepoly',
data = world.clust,
color = ~pal(`Enabling profile`),
weight = 0.9,
#opacity = 1,
popup = pop_up2$popup,
fillOpacity = 0.8,
options = pathOptions(pane = "layer1")) %>% stopSpinner()
}else if(input$var %in% as.character(unique(world.clust$Country))){
bounds <- unname(st_bbox(st_buffer((world.clust %>% filter(Country == input$var)), 1)))
leafletProxy('enabling_map') %>%
addSpinner() %>%
startSpinner(options = list("lines" = 7, "length" = 20)) %>%
clearGroup(c('basepoly', 'countrypoly', 'profilepoly')) %>%
addPolygons(
group = 'countrypoly',
data = filter(world.clust, Country == input$var),
color = ~pal(`Enabling profile`),
weight = 0.9,
#opacity = 1,
popup = filter(pop_up2, Country == input$var)$popup,
fillOpacity = 0.8,
options = pathOptions(pane = "layer1")) %>%
flyToBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>% stopSpinner()
}else if(input$var %in% c('Enabling profile 1', 'Enabling profile 2', 'Enabling profile 3',
'Enabling profile 4', 'Enabling profile 5', 'Enabling profile 6')){
profile <- strsplit(input$var, '')[[1]][18]
bounds <- unname(st_bbox(st_buffer((world.clust %>% filter(`Enabling profile` == profile)), 1)))
leafletProxy('enabling_map') %>%
addSpinner() %>%
startSpinner(options = list("lines" = 7, "length" = 20)) %>%
flyToBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
clearGroup(c('basepoly', 'countrypoly', 'profilepoly')) %>%
addPolygons(group = 'profilepoly',
data = filter(world.clust, `Enabling profile` == profile),
color = ~pal(`Enabling profile`),
weight = 0.9,
#opacity = 1,
popup = filter(pop_up2, `Enabling profile` == profile)$popup,
fillOpacity = 0.8,
options = pathOptions(pane = "layer1")) %>% stopSpinner()
}
}) # end observe
} #end server