【问题标题】:Countdown Timer in R shiny?R中的倒数计时器闪亮吗?
【发布时间】:2016-09-12 19:52:31
【问题描述】:

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

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

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

【问题讨论】:

    标签: r timer shiny


    【解决方案1】:

    以下代码应该这样做(假设事件仅提前 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
    

    【讨论】:

      猜你喜欢
      • 2020-06-19
      • 2019-05-20
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多