4

In Shiny, when I try to update any airDatePickerInput using the updateAirDateInput function, the date updates incorrectly.

If I tell updateAirDateInput to set the date as "2020-02-01", it will set the date to "2020-01-01", 1 day less than I want. Why??

Is this a bug? Do I have to increment the day I want + 1?

Here is an example which shows what I am talking about, press the button to set the date to "1999-01-01" and the app will incorrectly set the date to the last day of 1998

library(shiny)
library(shinyWidgets)

shinyApp(
    ui = fluidPage(
        fluidRow(
            column(
                width = 12,
                htmlOutput("someDate", inline = TRUE)          
            )
        ),
        fluidRow(
            column(
                width = 12,
                actionButton("b1", "Update Date")
            )
        )
    ),
    server = function(input, output, session) {
        #data$date <- format(as.Date(data$date, origin="1970-01-01"), "%m/%d/%Y")
        output$someDate <- renderUI({
            airDatepickerInput(
                "someDate",
                label = "Date",
                value = NULL,
                multiple = FALSE,
                range = FALSE,
                timepicker = FALSE,
                separator = " - ",
                placeholder = NULL,
                dateFormat = "yyyy-mm-dd",
                minDate = NULL,
                maxDate = NULL,
                disabledDates = NULL,
                view = c("days", "months", "years"),
                minView = c("days", "months", "years"),
                monthsField = c("monthsShort", "months"),
                clearButton = FALSE,
                todayButton = FALSE,
                autoClose = FALSE,
                timepickerOpts = timepickerOptions(),
                position = NULL,
                update_on = c("change", "close"),
                addon = c("right", "left", "none"),
                language = "en",
                inline = FALSE,
                width = NULL
            )
        })   
        observeEvent(input$b1, {
            updateAirDateInput(session, "someDate", value = as.character("1999-01-01"))
        })
    }
)
bretauv
  • 7,756
  • 2
  • 20
  • 57
Frank
  • 952
  • 1
  • 9
  • 23
  • Can you try installing development version from GitHub (https://github.com/dreamRs/shinyWidgets) and see if it still happen.Otherwise that can be a bug due to different timezone between R and your browser – Victorp Apr 28 '20 at 06:51
  • I don't want to risk updating to a dev version since I don't want to affect functionality of currently running apps. But your answer is interesting. That may mean that different users see different dates than the one I want based on time zones, even though I am not setting a time? – Frank Apr 28 '20 at 17:50
  • Normally, no. I'm just trying to guess what can be going on. You should open an issue on GitHub and include results of `sessioninfo::session_info()` and if possible value of `new Date()` from yours browser JavaScript console – Victorp Apr 29 '20 at 08:06
  • @Victorp I am having the exact same issue. I installed the dev version to no avail. – Giovanni Colitti Mar 05 '22 at 01:13

0 Answers0