shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

updateAirDateInput updates dates by lagging one month

Open barisguven opened this issue 2 years ago • 6 comments

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.

barisguven avatar Jan 11 '23 00:01 barisguven

I don't see the problem, must be a timezone issue, i'm in Europe/Paris (CET). Which version of shinyWidgets are you using ?

pvictor avatar Jan 12 '23 15:01 pvictor

It's version 0.7.5. I am in America/New_York.

I attach a picture of the app when the checkbox is checked.

Screenshot 2023-01-12 at 10 21 55 AM

barisguven avatar Jan 12 '23 15:01 barisguven

Here is an app that uses shiny's own dateRangeInput function. The same problem does not emerge here.

barisguven avatar Jan 13 '23 20:01 barisguven

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.

Andryas avatar Jun 28 '23 14:06 Andryas

@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.

Andryas avatar Jun 28 '23 15:06 Andryas

Thanks @Andryas. It seems setting seconds to 01 ("00:00:01") will do as well.

barisguven avatar Jul 01 '23 15:07 barisguven