R shiny中的倒计时计时器?

7

我想在我的闪亮App中显示当前时间。因此,我可以使用Sys.time()

function(input, output, session) {
  output$currentTime <- renderText({
    invalidateLater(1000, session)
    paste("The current time is", Sys.time())
  })
}

我想知道是否可以根据当前时间编写倒计时器,例如针对即将到来的事件?

1个回答

8
以下代码应该可以实现(假设事件只有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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接