javascriptrshinywidgethtml-framework-7

R shiny: one day difference between date selected on widget and returned date


The date returned by shinyMobile's f7DatePicker widget is one day before the actual date selected by the user.

I am based in France and everything works fine locally. The issue arises when deploying my app to shinyapps.io. Screenshots and a MRE below. Deployed MRE here.

server.R

library(shinyMobile)
# tried adding Sys.setenv(TZ='UTC'), to no avail

function(input, output, session) {
  output$date_output = renderUI(HTML(paste(input$date_input)))
}

ui.R

library(shinyMobile)

f7Page(
  f7DatePicker(
    'date_input',
    'Date entered by user:',
    value = NULL,
    maxDate = Sys.Date(), # tried setting to NULL, to no avail
    dateFormat = 'yyyy-mm-dd' # tried changing to 'mm-dd-yyyy' per https://stackoverflow.com/questions/7556591/is-the-javascript-date-object-always-one-day-off/31732581#31732581, to no avail
  ),
  div(style='padding-left:20px;',
    h5('Date recorded by the system:'),
    uiOutput('date_output')
  )
)

= = = = Local (no problem): = = = =

image

= = = = Remote (one day discrepancy!): = = = =

image

PS. I tried with Shiny's default dateInput and shinyWidgets' airDatePicker. None of them suffer from the issue, but unfortunately, they do not seem to be compatible with shinyMobile in terms of UI.

PPS. I think the solution might lie in this SO answer. Seems to be an issue related to different standards that javascript uses in different situations, and conversion to UTC (or not). If this is indeed the cause of the issue, that would require editing the js part of the R Shiny widget I guess, but I am not literate in javascript...

I would be grateful for any help or tip. Thanks!


Solution

  • A fix to this issue was provided by the author of the shinyMobile package, David Granjon, via this commit. Many thanks to him!

    And here is the link to the GitHub thread: https://github.com/RinteRface/shinyMobile/issues/204#issuecomment-1079532866