R_FF92 R_FF92 - 1 month ago 8x
R Question

Countdown Timer in R shiny?

I want display the current time in my shiny App. Therefore, I can use


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

I am wondering if it is also possible to code a countdown timer depending on the current time for e.g. an upcoming event?


The following code should do (let's assume the event is only 4 mins ahead):

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')

with the following output:

The time remaining for the Event: 226 secs