Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Countdown Timer in R shiny?

Tags:

r

timer

shiny

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

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?

like image 388
R_FF92 Avatar asked Sep 12 '16 11:09

R_FF92


1 Answers

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
like image 118
Sandipan Dey Avatar answered Nov 01 '22 12:11

Sandipan Dey