R闪亮的倒数计时器?

R_F*_*F92 7 r timer shiny

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

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

我想知道是否也可以根据例如即将举行的活动的当前时间来编码倒数计时器?

San*_*Dey 6

下面的代码应该做(让我们假设事件只提前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')
  })
Run Code Online (Sandbox Code Playgroud)

具有以下输出:

The time remaining for the Event: 226 secs
Run Code Online (Sandbox Code Playgroud)