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.
library(shiny)
shinyApp(
ui = fluidPage(
uiOutput("interaction_slider"),
verbatimTextOutput("breaks")
),
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],order.by=strptime(df[,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({
sliderInput(
"slider",
"Select Range:",
min = min(time(timeSeries)),
max = max(time(timeSeries)),
value = c(min, max)
)
})
brks <- reactive({
req(input$slider)
seq(input$slider[1], input$slider[2], length.out = 10)
})
output$breaks <- brks
}
)