[英]Trigger code in a Shiny app after a specific time each day
I have an app that currently is set up to run when the first user accesses it each morning.我有一个应用程序,当前设置为在每天早上第一个用户访问它时运行。 That works very well, however, we occasionally have a very early riser access it before the data is ready, and then it must be updated manually.
这非常有效,但是,我们偶尔会在数据准备好之前让一个非常早的人访问它,然后必须手动更新它。
What I would like to do is alter the below code to run when the first user access the app after a specific time, say 5 AM CST.我想要做的是更改以下代码以在特定时间后第一个用户访问该应用程序时运行,例如 CST 凌晨 5 点。 I can't wrap my head around how to use today() along with a specific time.
我无法理解如何使用 today() 以及特定时间。 The way it works now is very simple, we just like at the file info for the CSV & if it's not been updated today we run the code;
它现在的工作方式非常简单,我们就像 CSV 的文件信息,如果今天没有更新,我们运行代码; I just need to add a specific hour in the morning so that it only works after a certain time.
我只需要在早上添加一个特定的小时,以便它只在特定时间后工作。
FileInfoClaim = file.info("claimallocator.csv")
FileInfoClaim$mtime <- anydate(FileInfoClaim$mtime)
claimrenderer <- ifelse(FileInfoClaim$mtime==today(), "yes", "no")
Working with dates and times can be tricky.处理日期和时间可能很棘手。 The below minimal example should do what you're after:
下面的最小示例应该可以满足您的需求:
library("shiny")
ui <- fluidPage(
)
server <- function(session, input, output) {
#Check if its after 5am (runs once at app startup)
if(Sys.time() > ISOdatetime(format(Sys.time(),'%Y'), format(Sys.time(),'%m'), format(Sys.time(),'%d'), 5, 0, 0)) {
showNotification("Its after 5am")
} else {
showNotification("Its before 5am")
}
}
shinyApp(ui = ui, server = server)
Everything is done in the local timezone.一切都在当地时区完成。 This could cause issues if you span multiple timezones, for example if you deploy your app remotely.
如果您跨越多个时区,这可能会导致问题,例如,如果您远程部署您的应用程序。
If you haven't already I'd suggest looking at lubridate
, a popular package which makes dealing with dates and times much easier.如果您还没有,我建议您查看
lubridate
,这是一个流行的软件包,可以更轻松地处理日期和时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.