-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
188 lines (152 loc) · 8.33 KB
/
server.R
File metadata and controls
188 lines (152 loc) · 8.33 KB
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
function(input, output, session) {
# showModal(modalDialog(
# title = "REDIRECTING"
# ))
# # ONLY TURN THIS ON WHEN REDIRECTING (e.g. ON GLOBALARCHIVE ACCOUNT)
# session$sendCustomMessage("mymessage", "mymessage")
observe({
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[['park']])) {
print(query[['park']])
updateSelectInput(session,
"park",
choices = c("Geographe Marine Park" = "Geographe Bay", # first part is bit user sees
"Ningaloo Marine Park" = "Ningaloo",
"South-west Corner Marine Park" = "South-west Corner",
"Abrolhos Marine Park" = "Abrolhos",
"Montebello Islands Marine Park" = 'Montebello'),
selected = query[['park']])
}
})
# Filter data to selected marine park (should make plotting faster) ----
map.dat <- reactive({
req(input$park)
dat %>%
dplyr::filter(marine.park %in% input$park) %>%
glimpse()
})
# Create leaflet explore map ----
output$imagery.leaflet <- renderLeaflet({
# map.dat <- map.dat() # call in filtered data
map.dat <- dat
boss.habitat.highlights.popups <- filter(map.dat, source %in% c("boss.habitat.highlights"))
bruv.habitat.highlights.popups <- filter(map.dat, source %in% c("bruv.habitat.highlights"))
fish.highlights.popups <- filter(map.dat, source %in% c("fish.highlights"))
threed.model.popups <- filter(map.dat, source %in% c("3d.model"))
image.popups <- filter(map.dat, source %in% c('image'))
# Having this in the global.R script breaks now - make icons on server side
icon.bruv.habitat <- iconList(blue = makeIcon("images/marker_green.png", iconWidth = 40, iconHeight =40))
icon.boss.habitat <- iconList(blue = makeIcon("images/marker_pink.png", iconWidth = 40, iconHeight =40))
icon.fish <- iconList(blue = makeIcon("images/marker_yellow.png", iconWidth = 40, iconHeight =40))
icon.models <- iconList(blue = makeIcon("images/marker_purple.png", iconWidth = 40, iconHeight =40))
lng1 <- min(map.dat$longitude)
lat1 <- min(map.dat$latitude)
lng2 <- max(map.dat$longitude)
lat2 <- max(map.dat$latitude)
leaflet <- leaflet() %>%
addProviderTiles('Esri.WorldImagery', group = "World Imagery") %>%
addTiles(group = "Open Street Map")%>%
addControl(html = html_legend, position = "bottomleft") %>%
# flyToBounds(lng1, lat1, lng2, lat2)%>%
fitBounds(lng1, lat1, lng2, lat2)%>%
# stereo-BRUV habitat videos
addMarkers(data=bruv.habitat.highlights.popups,
icon = icon.bruv.habitat,
popup = bruv.habitat.highlights.popups$popup,
#label = bruv.habitat.highlights.popups$sample,
clusterOptions = markerClusterOptions(iconCreateFunction =
JS("
function(cluster) {
return new L.DivIcon({
html: '<div style=\"background-color:rgba(124, 248, 193, 0.9)\"><span>' + cluster.getChildCount() + '</div><span>',
className: 'marker-cluster'
});
}")),
group="BRUV Habitat imagery",
popupOptions=c(closeButton = TRUE,minWidth = 0,maxWidth = 700))%>%
# BOSS habitat videos
addMarkers(data=boss.habitat.highlights.popups,
icon = icon.boss.habitat,
popup = boss.habitat.highlights.popups$popup,
#label = boss.habitat.highlights.popups$sample,
clusterOptions = markerClusterOptions(iconCreateFunction =
JS("
function(cluster) {
return new L.DivIcon({
html: '<div style=\"background-color:rgba(248, 124, 179, 0.9)\"><span>' + cluster.getChildCount() + '</div><span>',
className: 'marker-cluster'
});
}")),
group="BOSS Habitat imagery",
popupOptions=c(closeButton = TRUE,minWidth = 0,maxWidth = 700))%>%
# stereo-BRUV fish videos
addMarkers(data=fish.highlights.popups,
icon = icon.fish,
popup = fish.highlights.popups$popup,
clusterOptions = markerClusterOptions(iconCreateFunction =
JS("
function(cluster) {
return new L.DivIcon({
html: '<div style=\"background-color:rgba(241, 248, 124,0.9)\"><span>' + cluster.getChildCount() + '</div><span>',
className: 'marker-cluster'
});
}")),
group="Fish highlights",
popupOptions=c(closeButton = TRUE,minWidth = 0,maxWidth = 700))%>%
# 3D models
addMarkers(data=threed.model.popups,
icon = icon.models,
popup = threed.model.popups$popup,
clusterOptions = markerClusterOptions(iconCreateFunction =
JS("
function(cluster) {
return new L.DivIcon({
html: '<div style=\"background-color:rgba(131, 124, 248,0.9)\"><span>' + cluster.getChildCount() + '</div><span>',
className: 'marker-cluster'
});
}")),
group="3D models",
popupOptions=c(closeButton = TRUE, minWidth = 0,maxWidth = 700)
)%>%
# Ngari Capes Marine Parks
addPolygons(data = ngari.mp, weight = 1, color = "black",
fillOpacity = 0.8, fillColor = "#7bbc63",
group = "State Marine Parks", label=ngari.mp$Name)%>%
# State Marine Parks
addPolygons(data = state.mp, weight = 1, color = "black",
fillOpacity = 0.8, fillColor = ~state.pal(zone),
group = "State Marine Parks", label=state.mp$COMMENTS)%>%
# Add a legend
addLegend(pal = state.pal, values = state.mp$zone, opacity = 1,
title="State Zones",
position = "bottomright", group = "State Marine Parks")%>%
# Commonwealth Marine Parks
addPolygons(data = commonwealth.mp, weight = 1, color = "black",
fillOpacity = 0.8, fillColor = ~commonwealth.pal(zone),
group = "Australian Marine Parks", label=commonwealth.mp$ZoneName)%>%
# Add a legend
addLegend(pal = commonwealth.pal, values = commonwealth.mp$zone, opacity = 1,
title="Australian Marine Park Zones",
position = "bottomright", group = "Australian Marine Parks")%>%
addLayersControl(
baseGroups = c("World Imagery","Open Street Map"),
overlayGroups = c("Fish highlights",
"BRUV Habitat imagery","BOSS Habitat imagery",
"3D models",
"State Marine Parks",
"Australian Marine Parks"), options = layersControlOptions(collapsed = FALSE)) #%>%
# hideGroup("Australian Marine Parks") %>%
# hideGroup("State Marine Parks")
return(leaflet)
})
# logos
output$logos <- renderImage({
return(list(
src = "images/logos-stacked.png",
width = "100%", #400
height = 600,
contentType = "image/png",
alt = "Face"
))
}, deleteFile = FALSE)
}