我想在我 Shiny 的应用程序中显示当前时间。因此,我可以使用Sys.time()
function(input, output, session) {
output$currentTime <- renderText({
invalidateLater(1000, session)
paste("The current time is", Sys.time())
})
}
我想知道是否还可以根据当前时间对倒数计时器进行编码,例如即将发生的事件?
最佳答案
下面的代码应该做(假设事件仅提前4分钟):
EventTime <- Sys.time() + 4*60
output$eventTimeRemaining <- renderText({
invalidateLater(1000, session)
paste("The time remaining for the Event:",
round(difftime(EventTime, Sys.time(), units='secs')), 'secs')
})
具有以下输出:
The time remaining for the Event: 226 secs