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
|
library(leaflet) #carte
library(plyr)
library(dplyr)
library(stringr)
library(tidyverse)
library(hms)
library(shinyWidgets)
heure <- c("15:16:00","17:56:00","18:17:00","20:00:00","21:00:00","22:22:00")
df <- data_frame(
heure = as_hms(heure),
latitude =c(46.50253,46.24055,46.22687,46.22042,46.20115,46.16915),
longitude = c(-1.788917,-1.360150,-1.337583,-1.317250,-1.279983,-1.245900),
vitesse =c(5.54,7.23,2.28,3.92,7.23,5.20),
angle = c(231,290,332,223,283,220)
)
ui <- fluidPage(
leafletOutput("carte"),
sliderInput(
inputId = "periode",
label = "Période de temps",
min = as.POSIXct("00:00:00",format = "%H:%M:%S"),
max = as.POSIXct("24:00:00",format = "%H:%M:%S"),
value = c(as.POSIXct("10:00:00",format = "%H:%M:%S"), as.POSIXct("23:59:59",format = "%H:%M:%S")),
timeFormat = "%H:%M:%S",
step=60),
actionBttn(inputId = "viz",
label = "Visualiser",
style = "pill",
color = "danger"),
sliderInput(
inputId = "point",
label = "Marquage sur un instant",
min = as.POSIXct("00:00:00",format = "%H:%M:%S"),
max = as.POSIXct("24:00:00",format = "%H:%M:%S"),
value = as.POSIXct("10:00:00",format = "%H:%M:%S"),
timeFormat = "%H:%M:%S",
step=60),
actionBttn(inputId = "mark",
label = "Marquer",
style = "pill",
color = "danger")
)
server <- function(input, output, session) {
heure_filtre <- eventReactive(input$viz,{
mini <- as.difftime(strftime(input$periode[1],format = "%H:%M:%S"),format = "%H:%M:%S")
maxi <- as.difftime(strftime(input$periode[2],format = "%H:%M:%S"),format = "%H:%M:%S")
data <- df[(df$heure > mini & df$heure < maxi),]
return(data)
},ignoreNULL = FALSE)
focus_heure <- eventReactive(input$mark,{
focus <- as.difftime(strftime(input$point,format = "%H:%M:%S"),format = "%H:%M:%S")
data <- df[(df$heure == focus),]
return(data)
})
output$carte <- renderLeaflet({
leaflet(heure_filtre()) %>%
addProviderTiles("OpenStreetMap.France") %>%
fitBounds(~min(longitude), ~min(latitude), ~max(longitude), ~max(latitude))
})
observe({
df <- heure_filtre()
leafletProxy("carte", data = df) %>%
clearMarkers() %>%
addCircleMarkers(lng = ~longitude, lat = ~latitude, radius = 6,stroke= FALSE, fillOpacity = 1)
})
observe({
df <- focus_heure()
proxy <- leafletProxy("carte", data = df)
proxy %>%
clearMarkers()
if (input$point){
proxy %>% addMarkers(lng = ~df$longitude, lat = ~df$latitude)}
})
}
shinyApp(ui, server) |