shinyWidgets
shinyWidgets copied to clipboard
updateAirDateInput updates dates by lagging one month
I have the following code in server function in my shiny app:
observeEvent(input$check_box, {
if (input$check_box) {
updateAirDateInput(inputId = "range",
value = list("1947-01-01", "2022-11-01")
)
}
})
After I deploy the app, once I check the reset check box, the date range is updated with one month (actually a day) lag. You can view the problem here with app being displayed in showcase mode.
I don't see the problem, must be a timezone issue, i'm in Europe/Paris (CET). Which version of shinyWidgets are you using ?
It's version 0.7.5. I am in America/New_York.
I attach a picture of the app when the checkbox is checked.

Here is an app that uses shiny's own dateRangeInput function. The same problem does not emerge here.
I am having the same issue here - I am working with dates like 2022-01-01, 2022-04-01 and when I use the updateAirDateInput it is lagging all those dates one month back.
But in my case it only happen in my shiny in a dockerfile, locally it is working fine. Both packages are in the same version.
@barisguven I just figure it out.
To solve the problem when you update the date you need to do something like this
shinyWidgets::updateAirDateInput("input", value = "2022-01-01 06:00:00")
If you check the function shinyWidgets::updateAirDateInput
function (session = getDefaultReactiveDomain(), inputId, label = NULL,
value = NULL, clear = FALSE, options = NULL, show = FALSE,
hide = FALSE)
{
stopifnot(is.logical(clear))
to_ms <- function(x) {
if (is.null(x))
return(NULL)
1000 * as.numeric(as.POSIXct(as.character(x), tz = Sys.timezone()))
}
if (!is.null(value)) {
value <- as.character(toJSON(x = to_ms(value), auto_unbox = FALSE))
}
if (!is.null(options)) {
options$minDate <- to_ms(options$minDate)
options$maxDate <- to_ms(options$maxDate)
}
if (!is.null(options$disabledDates)) {
options$disabledDates <- list1(options$disabledDates)
}
if (!is.null(options$highlightedDates)) {
options$highlightedDates <- list1(options$highlightedDates)
}
message <- dropNulls(list(id = session$ns(inputId), label = label,
value = value, clear = isTRUE(clear), options = dropNulls(options),
show = isTRUE(show), hide = isTRUE(hide)))
session$sendInputMessage(inputId, message)
}
this part here value <- as.character(toJSON(x = to_ms(value), auto_unbox = FALSE))
is lagging the date.
Thanks @Andryas. It seems setting seconds to 01 ("00:00:01") will do as well.