简体   繁体   English

每天特定时间后在 Shiny 应用程序中触发代码

[英]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.

相关问题 R在特定时间而非特定间隔触发的闪亮反应时间 - R Shiny reactive time to trigger at specific time and not specific interval 操作按钮在闪亮的应用程序中第二次按下后起作用 - Actionbuttons work after the second time they are pressed in a shiny app 如何在闪亮的应用程序中延长活动代码突出显示的时间? - How to extend time of active code highlight in a shiny app? Shiny app的代码分析? - Code profiling for Shiny app? 如何在我的 Shiny 应用程序中显示 plot“到达时间”? 每个“Id”和“Arrival time”都有重复项 - How can I plot "Arrival time" in my Shiny app? There are duplicates of each "Id" and "Arrival time" 更改 shiny 中的 textOutput() 后触发反应 - Trigger a reaction after change of textOutput() in shiny 根据每次按下任何 actionButton() 在闪亮的应用程序中显示不同的图像对 - Display different pair of images in a shiny app based on each time any actionButton() is pressed Shiny 用于创建自举正态分布的应用程序不会每次使用 actionButton 刷新。 如何刷新plot? - Shiny app for creating bootstrapped normal distribution not refreshing each time with actionButton. How to refresh plot? 如何在闪亮的Web应用程序中按特定的时间间隔一个接一个地显示句子中的单词? - How to display word from a sentence one after another in specific time interval in shiny web application? 第一次启动 shiny 应用程序时默认显示 Select 特定 tabItem() - Select specific tabItem() to be displayed by default when shiny app is launched for first time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM