I am trying to implement updateDateTimeRangePickerInput(session, inputId, from, to)
into an app and I am having trouble understanding what a session parameter would be. The function requires a session parameter, as shown from Warning: Error in updateDateTimeRangePickerInput: argument "session" is missing, with no default
when I do not input one. From a previous question on stackoverflow, a session object is the relationship between a user and shiny, i.e. onSessionEnded()
runs when the user disconnects from the client. But I am confused on how that would apply to my specific case, would I use sendInputMessage(inputId, message)
?
library(shiny)
library(ggplot2)
library(dplyr)
library(DateTimeRangePicker)
ui <- fluidPage(
fileInput("csv_input", "Select file", accept = ".csv"),
DateTimeRangePickerInput('date_range'),
actionButton('run', 'Run'),
plotOutput('plot')
)
server <- function(input,output){
data_input <- reactive({
req(input$csv_input)
df <- read.csv(input$csv_input$datapath)
return(df)
})
data_input_0 <- reactive({data_input() |> mutate(y = lubridate::ymd_hms(timestamp))
})
data_filtered <- eventReactive(input$run,{
filter(data_input_0(), as.POSIXct(timestamp) >= as.POSIXct(input$date_range[1]) & as.POSIXct(timestamp) <= as.POSIXct(input$date_range[2]))
})
observeEvent(data_input(),{
updateDateTimeRangePickerInput(session = ,inputId = "date_range", from = min(as.POSIXct(data_input()$timestamp)),
to = max(as.POSIXct(data_input()$timestamp)),
)
})
output$plot <- renderPlot(
ggplot(data_filtered(), aes(x = timestamp, y = SOEC_FC_0200_PIDPI_VAL0))+geom_point()
)
}
shinyApp(ui = ui, server = server)
Data if needed:
structure(list(timestamp = c("2024-06-11 14:00:00.0076393", "2024-06-11 14:00:01.0134811",
"2024-06-11 14:00:02.0112244", "2024-06-11 14:00:03.0090309",
"2024-06-11 14:00:04.0058750"), timestamp_utc = c("2024-06-11 18:00:00.0076393",
"2024-06-11 18:00:01.0134811", "2024-06-11 18:00:02.0112244",
"2024-06-11 18:00:03.0090309", "2024-06-11 18:00:04.0058750"),
sequence_number = 56500303:56500307, SOEC_EC_0510_PIDPI_VAL0 = c(151.346252441406,
151.346252441406, 151.323455810547, 151.351745605469, 151.355331420898
), SOEC_FC_0200_PIDPI_VAL0 = c(3.9853515625, 3.99609375,
4.017578125, 4.0068359375, 4.0068359375)), row.names = c(NA,
5L), class = "data.frame")