In Shiny for R, why does Sys.Date() return yesterd

2019-02-27 10:06发布

I have a dateInput in my ui.R as follows:

dateInput("asOfDateTime", label = "As Of", value = Sys.Date(), max = Sys.Date())

For 2015-05-15, this gives the dateInput a default value of 2015-05-14.

However, when I run Sys.Date() in the console on 2015-05-15, I get the correct value: 2015-05-15.

Why does Shiny give yesterday's date inside my app?

标签: r date input shiny
1条回答
叛逆
2楼-- · 2019-02-27 10:22

That does sound weird. I am just starting on Shiny so do not know for sure.

COULD IT BE

  1. Timezone?? Maybe Sys.timezone() is different on their servers?

    Have you tried formatting the date for your timezone?

  2. Caching problem??

    Could the value be cached from an old instance? But I take it you are running this within your Shinyserver{ ... code} not above. Try a rebuild in the Dashboard?

BUT HERE IS SOLUTION

Set value to NULL (see helpfile)

value The starting date. Either a Date object, or a string in yyyy-mm-dd format. If NULL (the default), will use the current date in the client's time zone.

It will default to your date in your timezone.

dateInput("asOfDateTime", label = "As Of", 
                                    value = NULL, max = Sys.Date())

gave me today's date

ShinyDateInputEG

查看更多
登录 后发表回答