Error in getSliderType: Type mismatch for 'min', 'max' and 'value'. Each must be Date, POSIXt or number. Dynamic min max values for date/time for inputslider R

I'm trying to set up an input slider based on the date/time values in a time series. When I try to run the code, I get the error, "Error in getSliderType: Type mismatch for min, max, and value. Each must be Date, POSIXt, or number." When I check the min and max values, they are POSIXt. Here's my code.


  ui = fluidPage(
  server = function(input, output, session) {
    df <- data.frame (dateTime = c("2019-08-20 16:00:00",
                   "2019-08-20 16:00:01",
                   "2019-08-20 16:00:02",
                   "2019-08-20 16:00:03",
                   "2019-08-20 16:00:04",
                   "2019-08-20 16:00:05"),
      var1 = c(9, 8, 11, 14, 16, 1),
      var2 = c(3, 4, 15, 12, 11, 19),
      var3 = c(2, 11, 9, 7, 14, 1)
    timeSeries <- as.xts(df[,2:4],[,1], format="%Y-%m-%d %H:%M:%S"))
    print (paste(min(time(timeSeries)),is.POSIXt(min(time(timeSeries))),sep=' '))
    print (paste(max(time(timeSeries)),is.POSIXt(max(time(timeSeries))),sep=' '))
    output$interaction_slider <- renderUI({
        "Select Range:",
        min   = min(time(timeSeries)),
        max   = max(time(timeSeries)),
        value = c(min, max)
    brks <- reactive({
      seq(input$slider[1], input$slider[2], length.out = 10)
    output$breaks <- brks

You are getting that error message because you haven't defined min, and max variables, if I change this line, it works

value = c(min(time(timeSeries)), max(time(timeSeries)))

BTW, you are missing some library calls to make your example reproducible

1 Like

Yes, thank you. It works with your fix.

@sanovogo would you mind if I used your code as a case study for making a reprex?

Yes, please feel free to use my code.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.