2016-09-12 55 views
5

我想在我閃亮的應用程序中顯示當前時間。因此,我可以使用Sys.time()R閃亮的倒數計時器?

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

我想知道如果它也可以根據當前的時間爲例如編碼一個倒計時的計時器即將舉行的活動?

回答

5

下面的代碼應該這樣做(讓我們假設事件是隻領先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