-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
97 lines (80 loc) · 2.96 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
server <- function(input, output, server) {
output$vt_selected = renderUI({
selectInput("vt_selected", label = h4("Vessel type"),
choices = c("", sort(unique(data$ship_type))), selected = NULL)
})
observeEvent(input$vt_selected,{
output$vessels_selected = renderUI({
vessels <- data %>%
filter(ship_type == input$vt_selected) %>%
distinct(SHIPNAME) %>% pull(SHIPNAME)
selectInput(inputId = "vessels_selected", #name of input
label = h4("Vessel"), #label displayed in ui
choices = c("", sort(unique(vessels))), #calls list of available cities
selected = NULL)
})
})
filteredData <- reactive({
summarizeDistance(data = data,
ShipType = input$vt_selected,
VesselName = input$vessels_selected,
method = input$method)
})
output$Map <- renderLeaflet({
leaflet() %>% addTiles()%>%
addProviderTiles(providers$Esri.WorldPhysical)
})
shiny::observeEvent(req(input$vessels_selected != '' ), {
tpoints <- filteredData()[[1]]
allpoints <- filteredData()[[2]]
labels_ag <- lapply(seq(nrow(tpoints)), function(i) {
paste0(
'<b>', 'Basic information','</b><br>',
'Vessel: ',
tpoints[i, "SHIPNAME"][[1]],'</b><br>',
'Type: ',
tpoints[i, "ship_type"][[1]],
'<br>', 'Date: ',
tpoints[i, "DATETIME"][[1]]
)
})
leafletProxy("Map", data = allpoints)%>%
clearMarkers() %>%
clearShapes() %>%
addAwesomeMarkers(data = tpoints,
lng = ~ LON, lat = ~ LAT,
label = lapply(labels_ag, htmltools::HTML),
icon = makeAwesomeIcon(
icon = "ship",
markerColor = "darkblue",
library = "fa",
iconColor = "#FFFFFF"
)) %>%
addMiniMap(toggleDisplay = TRUE,
position = "bottomleft") %>%
flyToBounds(~min(LON), ~min(LAT), ~max(LON), ~max(LAT))%>%
addPolylines(data = tpoints,
lng= ~ LON,
lat= ~ LAT,
color= 'red') %>%
addPolylines(data = allpoints,
lng= ~ LON,
lat= ~ LAT,
color= 'blue')
})
observeEvent(req(input$vessels_selected != ''), {
output$distance <-
renderText({
paste("In our data set, the ",input$vessels_selected,
" (a",input$vt_selected ," vessel) ",
"traveled for a maximum of ",
round(filteredData()[[1]]$DISTANCE[1],2),
"m. This trip happened between",
filteredData()[[1]]$DATETIME[1], " and ",
filteredData()[[1]]$DATETIME[1], ".")
})
})
observeEvent(req(input$method == 'Raster'), {
world <- st_read(system.file("shapes/world.gpkg", package="spData"))
})
}