在Shiny for R中,为什么Sys.Date()在dateInput中返回昨天的日期? [英] In Shiny for R, why does Sys.Date() return yesterday's date inside a dateInput?

查看:517
本文介绍了在Shiny for R中,为什么Sys.Date()在dateInput中返回昨天的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 ui.R 中有一个 dateInput ,如下所示:

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

对于 2015-05-15 ,这给了 dateInput 默认值 2015-05-14



但是,当我在 2015年的控制台中运行 Sys.Date() 05-15 ,我得到正确的值: 2015-05-15



为什么Shiny给我的应用程序中的昨天的日期?

解决方案

听起来很奇怪我刚刚从Shiny开始,所以不知道肯定。



可以


  1. 时区?? 也许 Sys.timezone()在他们的服务器上是不同的? p>

    您是否尝试格式化您的时区的日期?


  2. 缓存问题



    一个旧实例?但我认为你正在运行这个在你的Shinyserver {...代码}不在上面。尝试在仪表板中重建?


但这里是解决方案



设置为 NULL 请参阅helpfile


value开始日期。 Date对象或yyyy-mm-dd格式的字符串。如果NULL(默认值)将使用客户端时区中的当前日期。


它将默认为您的时区的日期

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

给我今天的日期




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?

解决方案

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

这篇关于在Shiny for R中,为什么Sys.Date()在dateInput中返回昨天的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆