-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
677 lines (584 loc) · 26 KB
/
Copy pathapp.R
File metadata and controls
677 lines (584 loc) · 26 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#Author: Pauline Cairns Date: 8/8/19
#Runner file to create dashboard
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#inspiration for dashboard items and code structure - https://shiny.rstudio.com/gallery/
#all sourced from the packages install facility within RStudio
#in turn these are sourced from the cran repository
#https://cran.r-project.org/
#Load packages
library(shiny)
library(shinydashboard)
library(leaflet)
library(sf)
library(dplyr)
library(zoo)
library(xts)
library(dygraphs)
#Load data
source('filter.R')
#set up messages, notifications, and tasks - currently list of items fixed
messages <- dropdownMenu(type = "messages",
messageItem(
from = "Tug",
message = "Maintencance request - check fuel",
icon = icon("ship")
),
messageItem(
from = "New User",
message = "Looking to berth on 29th December",
icon = icon("question"),
time = "2017-12-05 13:45"
),
messageItem(
from = "Alert",
message = "Port oversubscribed",
icon = icon("bell"),
time = "2017-12-01"
)
)
notifications<-dropdownMenu(type = "notifications",
notificationItem(
text = "5 new users today",
icon("users")
),
notificationItem(
text = "12 cars delivered ready for load onto vessel",
icon("truck"),
status = "success"
),
notificationItem(
text = "Speed of vessel approaching - too fast",
icon = icon("exclamation-triangle"),
status = "warning"
)
)
tasks<-dropdownMenu(type = "tasks", badgeStatus = "success",
taskItem(value = 95, color = "green",
"All visitors safety briefing instructions updated"
),
taskItem(value = 50, color = "aqua",
"Idle time project"
),
taskItem(value = 40, color = "red",
"Dashboard project"
))
# Create UI of dashboard
ui <- dashboardPage(
#Set up header and header contents
dashboardHeader(
# Application title
title="AIS - NE Scotland",
#info in header bar
messages,notifications, tasks
),
#Set up sidebar with tab options
dashboardSidebar(
sidebarMenu(
id="tabs",
#list of tabs
#icons from https://fontawesome.com/icons?d=gallery
menuItem("Dashboard - Home", tabName="dashboard", icon=icon("dashboard")),
menuItem("Ports", tabName= "ports", icon = icon("anchor")),
menuItem("Routes", tabName="routes", icon = icon("map-pin")),
menuItemOutput("menuitem")
#end of dashboardsidebar - closing bracket
)
#end of sidebarmenu - closing bracket
),
#Set up body of dashboard
dashboardBody(
# set up bookmark facility
#bookmarkButton()
#link body content to tab selected from sidebar
tabItems(
#set up body of dashboard-home tab
tabItem(tabName="dashboard",
#set up date range
fluidRow(dateRangeInput("inDateRange4", "Date range input: dd-mm-yyyy",
format = "dd/mm/yy", start= "2016-07-01", end="2017-12-04",
min= "2016-07-01", max="2017-12-04")),
#set up three port boxes with dropdown area selection
fluidRow(
column(width=4,
box(
title = "Aberdeen", width=NULL, status = "primary",solidHeader = TRUE,
collapsible = TRUE, collapsed=TRUE,
selectInput(inputId="aberdeen_pic_port",
label= "Choose area:",
choices = c("Aberdeen",
"Aberdeen_extended")),
"Unique vessels",
infoBoxOutput("uniquevesselsaberdeen")
)),
column(width=4,
box(title = "Montrose", width=NULL, status = "primary",solidHeader = TRUE,
collapsible = TRUE, collapsed=TRUE,
selectInput(inputId="montrose_pic_port",
label= "Choose a port:",
choices = c("Montrose",
"Montrose_extended")),
"Unique vessels",
infoBoxOutput("uniquevesselsmontrose")
)),
column(width=4,
box(title = "Peterhead", width=NULL, status = "primary",solidHeader = TRUE,
collapsible = TRUE, collapsed=TRUE,
selectInput(inputId="peterhead_pic_port",
label= "Choose a port:",
choices = c("Peterhead",
"Peterhead_extended")),
"Unique vessels",
infoBoxOutput("uniquevesselspeterhead"))
)),
#set up graph
fluidRow(
box(title = "Unique vessels within port boundaries", width=12, status = "primary",solidHeader = TRUE,
collapsible = TRUE,
dygraphOutput("ves_graph2", height=400),
h5(" Slider: shows total data period with highlighted section showing
section of data currently on display in the window"))
)
#dashboard-home tabitem closing bracket
),
#ports tab - body setup
tabItem(
tabName = "ports",
#dropdown for port selection & dropdown for date selection
fluidRow(
box( width=6,
selectInput(inputId="pick_ves_port",
label= "Choose a port:",
choices = c("Montrose","Montrose_extended", "Aberdeen",
"Aberdeen_extended", "Peterhead", "Peterhead_extended"
)
)
),
box(width=6,
dateRangeInput("inDateRange", "Date range input: dd-mm-yyyy",
format = "dd/mm/yy", start= "2016-07-01", end="2017-12-04",
min= "2016-07-01", max="2017-12-04")
)
),
#set up three info boxes - actual, target, progress
fluidRow(
infoBoxOutput("uniquevessels"), infoBoxOutput("target"),
infoBoxOutput("progressBox")
),
#set up graph
fluidRow(
box(title = "Unique vessels in period", width=12, status = "primary",solidHeader = TRUE,
collapsible = TRUE, collapsed=TRUE,
dygraphOutput("ves_graph", height=300)
)
),
#set up table
fluidRow(
box(collapsible = TRUE,collapsed=TRUE, width=12,status = "primary", solidHeader = TRUE,title = "Duration in port",
DT::dataTableOutput("port_table")
)),
#set up map
fluidRow(
box(width=12, solidHeader = TRUE, collapsible = TRUE, status="primary",
title="Map of port area", collapsed=TRUE,
dateInput("inDateRange3", "Select date:",
format = "dd/mm/yy", value= "2016-07-01",
min= "2016-07-01", max="2017-12-04"),
selectInput(inputId="pick_ves_port2",
label= "Choose an area:",
choices = c("Montrose", "Aberdeen",
"Peterhead")
),
leafletOutput("ves_harbour")
)
)
#ports tab -closing bracket
),
# routes tab setup
tabItem(
tabName="routes",
h2("Routes"),
#setup date range
dateRangeInput("inDateRange2", "Select period between 1 June to 14 June 2017",
format = "dd/mm/yy", start= "2017-06-01", end="2017-06-14",
min= "2017-06-01", max="2017-06-14")
,
#set up call to vessel type and vessel dropdown lists
fluidRow(column(width=6,
box(width=NULL,
uiOutput("type_selected"),
uiOutput("ves_selected"),
br()
)
),
#reset map button
column(width=3,
box(width = NULL,
actionButton("reset", "Reset map")
))),
#show map
fluidRow(
column( width = 12, leafletOutput("scotmap", width='750px', height='650px'))
)
#routes tab closing bracket
)
#tabitems - closing bracket
)
#closing dashboardbody - closing bracket
)
#dashboardpage - closing bracket
)
server <- function(input, output, session) {
#map -create and populate vessel type dropdown list
output$type_selected <- renderUI({
selectInput("pick_type", "Choose a vessel type:",
choices= c(Choose="", sort(unique(all_vessels$description))))
})
#map -create and populate vessel name dropdown list
output$ves_selected <- renderUI({
vessel_list<-all_vessels[all_vessels$description == input$pick_type, "Name"]
selectInput("pick_ves", "Choose a vessel:",
choices= c(Choose = "", sort(unique(vessel_list))
)
)
})
#map- create map and add markers based on selection above
output$scotmap <- renderLeaflet({
# inspiration taken from https://rstudio.github.io/leaflet/map_widget.html
req(input$inDateRange2)
uniq_name_ves<-filter(all_vessels, date(all_vessels$RecvTime) >=input$inDateRange2[1], date(all_vessels$RecvTime)<= input$inDateRange2[2],
all_vessels$Name==input$pick_ves)
fullmap<- leaflet()
fullmap <- setView(fullmap, lng = -2, lat = 57, zoom = 8)
# fullmap<- fitBounds(fullmap,lng1 =-8.1, lat1=55.1, lng2=1.1, lat2=61)
fullmap<- addTiles(fullmap, group = "OSM (default)")
fullmap<-addRectangles(fullmap, group ="Harbour boundaries", lng1=-2.096, lat1=57.176, lng2=-1.978 , lat2=57.101, weight=1, label="Aberdeen Harbour limits")
fullmap<-addRectangles(fullmap, group="Harbour boundaries", lng1=-2.476, lat1=56.708,
lng2=-2.413, lat2=56.701,weight=1,
label="Montrose Port limits")
fullmap<-addRectangles(fullmap, group="Harbour boundaries", lng1=-1.795, lat1=57.512,
lng2=-1.735, lat2=57.472,weight=1,
label="Peterhead harbour limits")
#Layers control
fullmap<-addLayersControl(fullmap,
baseGroups = c("OSM (default)"),
overlayGroups = c("Harbour boundaries"),
options = layersControlOptions(collapsed = FALSE)
)
#to allow colour of markers to change
a<- 1/length(uniq_name_ves$Latitude)
b<- 0
#draw markers
for(i in 1:length(uniq_name_ves$Latitude)){
b<- b+a
fullmap <- addCircles(fullmap, lng=uniq_name_ves$Longitude[i], lat= uniq_name_ves$Latitude[i], radius=15,
label = input$pick_ves, fillColor="red", fillOpacity = b, color="red",opacity = b )
}
fullmap
})
#map - reset button
observeEvent(input$reset,
{leafletProxy("scotmap") %>%
setView(lng = -2, lat = 57, zoom = 8)
})
#ports - set up ability for datasetInput function to change based on port selected
datasetInput <- reactive ({
switch(input$pick_ves_port,
"Montrose" = montrose,
"Montrose_extended" = montrose_extended,
"Aberdeen" = aberdeen,
"Aberdeen_extended" = aberdeen_extended,
"Peterhead" = peterhead,
"Peterhead_extended" = peterhead_extended
)
})
#ports map section - set up ability for dataset input function to change based on port selected
datasetInput2 <- reactive ({
switch(input$pick_ves_port2,
"Montrose" = montrose_extended,
"Aberdeen" = aberdeen_extended,
"Peterhead" = peterhead_extended
)
})
#homepage - set up ability for dataset input function to change based on port selected
montrosesetInput <- reactive ({
switch(input$montrose_pic_port,
"Montrose" = montrose,
"Montrose_extended" = montrose_extended
)
})
aberdeensetInput <- reactive ({
switch(input$aberdeen_pic_port,
"Aberdeen" = aberdeen,
"Aberdeen_extended" = aberdeen_extended
)
})
peterheadsetInput <- reactive ({
switch(input$peterhead_pic_port,
"Peterhead" = peterhead,
"Peterhead_extended" = peterhead_extended
)
})
#ports - set up info box counting number of unique vessels
output$uniquevessels <- renderInfoBox({
req(input$inDateRange)
count_in_port <- datasetInput() %>%
filter(date(RecvTime) >=input$inDateRange[1], date(RecvTime)<= input$inDateRange[2])
count_in_port<- length(unique(count_in_port$MMSI))
infoBox(
"Unique vessels",
count_in_port,
"in period",
icon = icon("ship"),
color = "blue"
)
})
#ports - progress box
output$target <- renderInfoBox({
req(input$inDateRange)
count_in_port <- datasetInput() %>%
filter(date(RecvTime) >=input$inDateRange[1], date(RecvTime)<= input$inDateRange[2])
count_in_port<- length(unique(count_in_port$MMSI))
infoBox(
"Target", paste0(as.integer(count_in_port*1.2)), icon = icon("list"),
"unique vessels",
color = "teal"
)
})
#homepage - set up info box for aberdeen counting number of unique vessels
output$uniquevesselsaberdeen <- renderInfoBox({
req(input$inDateRange4)
count_in_port_ab <- aberdeensetInput() %>%
#mutate(Date = str_sub(RecvTime, 1,10)) %>% # convert thtr_rel_date to Date format
filter(date(RecvTime) >=input$inDateRange4[1], date(RecvTime)<= input$inDateRange4[2])
count_in_port_ab<- length(unique(count_in_port_ab$MMSI))
infoBox(
"Unique vessels",
count_in_port_ab,
"in period",
icon = icon("ship"),
color = "blue",
width=NULL
)
})
#homepage - set up info box for montrose counting number of unique vessels
output$uniquevesselsmontrose <- renderInfoBox({
req(input$inDateRange4)
count_in_port_mn <- montrosesetInput() %>%
filter(date(RecvTime) >=input$inDateRange4[1], date(RecvTime)<= input$inDateRange4[2])
count_in_port_mn<- length(unique(count_in_port_mn$MMSI))
infoBox(
"Unique vessels",
count_in_port_mn,
"in period",
icon = icon("ship"),
color = "blue"
)
})
# homepage - set up info box for peterhead counting number of unique vessels
output$uniquevesselspeterhead <- renderInfoBox({
req(input$inDateRange4)
count_in_port_ph <- peterheadsetInput() %>%
filter(date(RecvTime) >=input$inDateRange4[1], date(RecvTime)<= input$inDateRange4[2])
count_in_port_ph<- length(unique(count_in_port_ph$MMSI))
infoBox(
"Unique",
count_in_port_ph,
"in period",
icon = icon("ship"),
color = "blue"
)
})
#ports - create graph
output$ves_graph<-renderDygraph({
# inspiration taken from https://rstudio.github.io/dygraphs/index.html
req(input$inDateRange)
date1<- input$inDateRange[1]
date2<- input$inDateRange[2]
#Works to calculate the number of distinct vessel
no_of_vessels <- datasetInput() %>% group_by(date(RecvTime)) %>%
summarize(distinct_vessels= n_distinct(MMSI))
#Make into a time series
no_of_vessels.ts <- xts(no_of_vessels[,2, drop=FALSE], order.by=as.Date(no_of_vessels$`date(RecvTime)`))
#Draw on graph
dygraph(no_of_vessels.ts, main="Number of unique vessels each day") %>%
dyRangeSelector(dateWindow =c(date1, date2)) %>%
dyOptions(drawPoints = TRUE, pointSize = 2)
})
#ports- createmap
output$ves_harbour<- renderLeaflet({
# inspiration taken from https://rstudio.github.io/leaflet/map_widget.html
req(input$inDateRange3)
port_selected <- datasetInput2() %>%
filter(date(RecvTime) ==input$inDateRange3)
m <- leaflet()
m <- setView(m, lng =mean(port_selected$Longitude), lat = mean(port_selected$Latitude), zoom = 10)
m <- addTiles(m, group = "OSM (default)")
m<-addRectangles(m, group="Harbour boundaries", lng1=-2.476, lat1=56.708,
lng2=-2.413, lat2=56.701,weight=1,
label="Montrose Port limits")
m<-addRectangles(m, group="Harbour boundaries", lng1=-1.795, lat1=57.512,
lng2=-1.735, lat2=57.472,weight=1,
label="Peterhead harbour limits")
m<-addRectangles(m, group ="Harbour boundaries", lng1=-2.096, lat1=57.176,
lng2=-1.978 , lat2=57.101, weight=1,
label="Aberdeen Harbour limits")
m <-addRectangles(m, group="Extended boundaries", lng1=-2.476, lat1=56.758,
lng2=-2.367, lat2=56.651,weight=1
#,label="Montrose extended"
)
m<-addRectangles(m, group="Extended boundaries", lng1=-1.795, lat1=57.542,
lng2=-1.695, lat2=57.442,weight=1
#,label="Peterhead extended"
)
m<-addRectangles(m, group ="Extended boundaries", lng1=-2.096, lat1=57.189,
lng2=-1.947, lat2=57.089, weight=1
#,label="Aberdeen extended"
)
m<-addLayersControl(m,
baseGroups = c("OSM (default)"),
overlayGroups = c("Harbour boundaries", "Extended boundaries"),
options = layersControlOptions(collapsed = FALSE),
position="bottomright")
for(i in 1:length(port_selected$Latitude)){
m <- addCircles(m, group = "OSM (default)", lng=port_selected$Longitude[i], lat= port_selected$Latitude[i],
label= port_selected$Name[i])
}
m
}
)
#ports -table
output$port_table <- DT::renderDataTable(DT::datatable({
req(input$inDateRange)
names_in_port<- datasetInput()%>%
filter(date(RecvTime)>=input$inDateRange[1], date(RecvTime)<= input$inDateRange[2])
#remove excess row and arrange order
names_in_port<- names_in_port[, -c(3:8,11)]
names_in_port<- names_in_port %>% arrange(MMSI, RecvTime, NavigationalStatus)
#set up new column changed - all cells given same initial value
names_in_port$changed<-1
#change status of changed if nav status goes from stopped to moving (99 will mean starting to move)
for(c in 1:(length(names_in_port$NavigationalStatus)-1)){
if((names_in_port$NavigationalStatus[c]==1 |
names_in_port$NavigationalStatus[c]==5) & (names_in_port$NavigationalStatus [c+1]==0))
{names_in_port$changed[c+1]<-99}
}
#change status of changed if nav status goes from moving to stopped (89 will mean stopping)
for(d in 1:(length(names_in_port$NavigationalStatus)-1)){
if((names_in_port$NavigationalStatus[d+1]==1 |
names_in_port$NavigationalStatus[d+1]==5) & (names_in_port$NavigationalStatus [d]==0))
{names_in_port$changed[d]<-89}
}
#remove excess rows where nav status moving and not about to change
names_in_port<-names_in_port%>% filter((NavigationalStatus==0 & changed==89)|
NavigationalStatus==5 | NavigationalStatus==1 |
(NavigationalStatus==0 & changed==99))
#new column set up called Date to take only date element of RecvTime
names_in_port$Date<- as.Date(names_in_port$RecvTime)
#remove RecvTime column as currently not required
names_in_port$RecvTime<- NULL
#set up new columns and populate all cells with the same value
names_in_port$Stopped_moving<- as.Date("2000-01-01")
names_in_port$Started_moving<- as.Date("2000-01-01")
#identify dates stopped moving
for(p in 1:(length(names_in_port$changed)-1)){
if(names_in_port$changed[p+1]==1 & names_in_port$changed[p]==89){
names_in_port$Stopped_moving[p+1]<-names_in_port$Date[p+1]
}
}
#idenfify dates stareted to move
for(q in 1:(length(names_in_port$changed)-1)){
if(names_in_port$changed[q]==1 & names_in_port$changed[q+1]==99){
names_in_port$Started_moving[q]<-names_in_port$Date[q]
}
}
#as dataset starts at 1 July 2016, may be some vessels stopped before that date and not yet moving
#set default stopped date to date data starts
for(r in 1:length(names_in_port$Date)){
if(names_in_port$Date[r]=="2016-07-01" & (names_in_port$NavigationalStatus[r]==5 &
names_in_port$changed[r]==1)){
names_in_port$Stopped_moving[r]<- names_in_port$Date[r]
}
}
#if both stopping and starting show no change in date - remove
names_in_port<- names_in_port%>% filter((Stopped_moving!="2000-01-01" |
Started_moving != "2000-01-01"))
#move stopping date up a row
for(u in 1:(length(names_in_port$Date)-1)){
if(names_in_port$Stopped_moving[u]== "2000-01-01"){
names_in_port$Started_moving[u-1]<- names_in_port$Started_moving[u]
}
}
#remove rows excess rows
names_in_port<- names_in_port %>% filter(Stopped_moving != "2000-01-01")
#data set ends at 4 Dec 2017 - for those vessels stopped at 4 Dec, show them moving on 5 Dec
#only required as can't currently get the column to show blank fields - needs to be fix
for(v in 1:length(names_in_port$Date)){
if(names_in_port$Started_moving[v]=="2000-01-01"){
names_in_port$Started_moving[v]<-"2017-12-05"
}
}
#remove excess columns
names_in_port$changed<- NULL
names_in_port$NavigationalStatus<- NULL
#duration
names_in_port$Duration_in_days<- names_in_port$Started_moving - names_in_port$Stopped_moving
#remove excess columns
names_in_port$Date<-NULL
names_in_port
}))
#port - target box - made up target of 120% of current amount of unique vessels - as with most targets it can never be met!
output$progressBox <- renderInfoBox({
req(input$inDateRange)
count_in_port <- datasetInput() %>%
filter(date(RecvTime) >=input$inDateRange[1], date(RecvTime)<= input$inDateRange[2])
count_in_port<- length(unique(count_in_port$MMSI))
infoBox(
"Progress", paste0(as.integer(count_in_port/(count_in_port*1.2)*100), "%"), icon = icon("list"),
color = "purple"
)
})
#date rangeinputs - set up to render a change if date changed
reactive({
input$inDateRange
})
reactive({
input$inDateRange4
})
#homepage - draw graph
output$ves_graph2<-renderDygraph({
# inspiration taken from https://rstudio.github.io/dygraphs/index.html
req(input$inDateRange4)
date1<- input$inDateRange4[1]
date2<- input$inDateRange4[2]
#Works to calculate the number of distinct vessel
no_of_vessels2 <-montrose %>% group_by(date(RecvTime)) %>%
summarize(montrose= n_distinct(MMSI))
#Make into a time series
no_of_vessels2.ts <- xts(no_of_vessels2[,2, drop=FALSE], order.by=as.Date(no_of_vessels2$`date(RecvTime)`))
no_of_vessels3 <-peterhead %>% group_by(date(RecvTime)) %>%
summarize(peterhead= n_distinct(MMSI))
#Make into a time series
no_of_vessels3.ts <- xts(no_of_vessels3[,2, drop=FALSE], order.by=as.Date(no_of_vessels3$`date(RecvTime)`))
no_of_vessels4<-aberdeen %>% group_by(date(RecvTime)) %>%
summarize(aberdeen= n_distinct(MMSI))
#Make into a time series
no_of_vessels4.ts <- xts(no_of_vessels4[,2, drop=FALSE], order.by=as.Date(no_of_vessels4$`date(RecvTime)`))
allports<- cbind(no_of_vessels2.ts,no_of_vessels4.ts, no_of_vessels3.ts)
#Draw on graph
dygraph(allports, main="Number of unique vessels each day") %>%
dyRangeSelector(dateWindow =c(date1, date2)) %>%
dyOptions(drawPoints = TRUE, pointSize = 2) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
highlightSeriesOpts = list(strokeWidth = 1.5)
)%>%
dyOptions(colors =c("steelblue", "seagreen", "blueviolet") )
})
}
# Run the application
shinyApp(ui = ui, server = server, enableBookmarking = "url")