Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(ggplot2)
- library(tidyr)
- library(dplyr)
- library(rlang)
- library(plotly)
- packageVersion('plotly')
- library(lubridate)
- library(base)
- library(leaflet)
- library(leaflet.extras)
- library(rdrop2)
- library(httr)
- library(rsconnect)
- token <- drop_auth()
- saveRDS(token, "droptoken.rds")
- ui <- fluidPage(
- tags$style(type="text/css",
- ".recalculating {opacity: 1.0;}"
- ),
- leafletOutput(outputId = "mainmap", height = 600)
- )
- server <- function(input, output, session){
- rsconnect::setAccountInfo(name='xxxxx',
- token='xxxxxxx',
- secret='xxxxxxxxx')
- drop_auth(key = "xxxxxx", secret = "xxxxxxx", rdstoken = "droptoken.rds")
- bw <- reactive({
- load_data_dropbox()
- })
- load_data_dropbox <- function() {
- invalidateLater(600000, session)
- bw <- drop_read_csv("ShipData_NMEA.csv", dtoken=token)
- }
- # Plot the latest position of the vessel
- ShipNames_DF <- reactive({
- bwtemp <- NULL
- ShipNames <- unique(as.character(bw()$ShipName))
- ShipNames_DF <- data.frame(ShipNames)
- ShipNames_DF$MaxDate <- as.POSIXct("1900-01-01 00:00:00")
- ShipNames_DF$Lat <- NA
- ShipNames_DF$Lon <- NA
- ShipNames_DF$GPSSpeed <- NA
- ShipNames_DF$WindSpeedTrue <- NA
- ShipNames_DF$WindDirectionTrue <- NA
- for (i in 1:nrow(ShipNames_DF)){
- bwtemp<- NULL
- bwtemp <- bw() %>%
- filter(ShipName == ShipNames_DF$ShipNames[i])
- bwtemp$DateTime <- as.POSIXct(bwtemp$DateTime)
- bwtemp <- bwtemp[1,]
- ShipNames_DF$MaxDate[i] <- bwtemp$DateTime[1]
- ShipNames_DF$Lat[i] <- bwtemp$Lat[1]
- ShipNames_DF$Lon[i] <- bwtemp$Lon[1]
- ShipNames_DF$GPSSpeed[i] <- bwtemp$GPSSpeed[1]
- ShipNames_DF$WindSpeedTrue[i] <- bwtemp$WindSpeedTrue[1]
- ShipNames_DF$WindDirectionTrue[i] <- bwtemp$WindDirectionTrue[1]
- }
- bwtemp <- NULL
- ShipNames_DF <- as.data.frame(ShipNames_DF)
- return(ShipNames_DF)
- })
- # To plot the last 24 hours sailing position to give indication on the heading
- Direction_DF <- reactive({
- bwtemp <- NULL
- ShipNames_DFin <- ShipNames_DF()
- Direction_DF <- NA
- for (i in 1:nrow(ShipNames_DFin)){
- bwtemp<- NULL
- bwtemp <- bw() %>%
- filter(ShipName == ShipNames_DFin$ShipNames[i])
- bwtemp <- bwtemp[1:144,]
- Direction_DF <- rbind(Direction_DF, bwtemp)
- }
- bwtemp <- NULL
- Direction_DF <- as.data.frame(Direction_DF)
- return(Direction_DF)
- list(df1)
- })
- output$mainmap <- renderLeaflet({
- ShipNames_DFin <- ShipNames_DF()
- Direction_DFin <- Direction_DF()
- leaflet(data) %>%
- setView(lng = 120, lat = -40, zoom = 2.8) %>%
- addTiles() %>%
- addTerminator(group = "Day or Night") %>%
- addCircleMarkers(data = ShipNames_DFin, lat = ~Lat, lng = ~Lon, label = ~MaxDate, weight = 1,
- labelOptions = labelOptions(noHide = T,
- textOnly = TRUE,
- direction = "bottom",
- style = list("color" = "black",
- "font-size" = "12px"))) %>%
- addPolylines(data = subset(Direction_DFin, ShipName == "Black Pearl"), lat = ~Lat, lng = ~Lon, color = "black", weight = 1.4, dashArray = '5, 5', group = "48hr sailed") %>%
- addLayersControl(
- overlayGroups = c("48hr sailed", "Day or Night"),
- options = layersControlOptions(collapsed = FALSE)
- )
- })
- }
- shinyApp(ui=ui, server=server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement