-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.R
More file actions
66 lines (56 loc) · 2.39 KB
/
Copy pathserver.R
File metadata and controls
66 lines (56 loc) · 2.39 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
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(leaflet)
if(!exists("getShipNames", mode="function")) source("db.R")
if(!exists("getShipObservations", mode="function")) source("db.R")
if(!exists("getLongestObservation", mode="function")) source("observations.R")
# Define server logic required to draw a histogram
shinyServer(function(input, output, session) {
# First we observe value of select_ship_types if it is changed we load
# new set of ship names
# Next we observe on select_ship_names if it is changed we load a new
# set of observations from which we select 2 consecutive points which
# have greatest distance.
# From the data set we visualize observations on the map, list the
# observations in the table and provide the distance.
observe({
x <- input$select_ship_types
getReactiveShipNames <- reactive({getShipNames(x)})
shipNames <- getReactiveShipNames()
updateSelectInput(session, "select_ship_names",
choices = shipNames
)
})
observe({
x <- input$select_ship_names
getReactiveObservations <- reactive({getShipObservations(x)})
observations <- getReactiveObservations()
if(nrow(observations)!=0){
results = getLongestObservation(observations)
distance <- attributes(results)$distance
observations <- attributes(results)$observations
observations$DATETIME <- as.POSIXct(observations$DATETIME, origin="1970-01-01")
output$data <- renderTable({
observations
})
output$mymap <- renderLeaflet({
leaflet(data = observations) %>%
addProviderTiles(providers$Stamen.TonerLite,
options = providerTileOptions(noWrap = TRUE)
) %>%
addMarkers(~LON, ~LAT, popup = ~DESTINATION) %>%
addPolylines(~LON, ~LAT)
})
output$observation_description <- renderText({
paste("The longest distance between 2 consecutive points is ", distance, " meters.")
})
}
})
})