Hi everyone,
I don't succeed to have a link between a sliderInput with hours and a reactive in order to change the hour range in my plot... can somebody help me ? thanks a lot
library(shiny)
library(ggplot2)
library(dplyr)
library(shinyTime)
library(lubridate) #variable temps
route_fond_degre <- c(1:10)
vitesse_fond_noeuds <- c(2:11)
heure <- c("01:05:30","01:05:31","01:05:32","01:05:33","01:05:34","01:05:35","01:05:36",
"01:05:37","01:05:38","01:05:39")
#pas sur que cela s'écrive comme ca mais si je fais class(heure) j'ai hms
df_test <- data.frame(heure, route_fond_degre, vitesse_fond_noeuds)
ui <- fluidPage(
sliderInput(inputId = "periode",
label = "Période",
min = as.POSIXct("10:00:00",format = "%H:%M:%S"),
max = as.POSIXct("23: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"),
#le slider s'affiche bien mais pas de lien avec le plot
plotOutput("graph1")
)
server <- function(input, output) {
date_filtre <- reactive({
mini <- as.POSIXct(input$periode[1])
maxi <- as.POSIXct(input$periode[2])
#df_test <- df_test %>% filter(heure > hms("10:00:00")) -> ce cas fonctionnait avant le sliderinput
data_sel <- df_test %>% filter(heure > mini & heure < maxi)
return(data_sel)
})
output$graph1 <- renderPlot({
g <- ggplot(date_filtre(), aes_string(x="heure", y = "route_fond_degre"))+
geom_point()
g
#j'ai mis un aes_string car je fais aussi changer le y en selectInput aussi avec choices = names(df_test)
})
}
shinyApp(ui=ui, server=server)