Save sys.time() when a long script finishes to execute in shiny


I would like to save the sys.time() when a long script finishes to execute in shiny.

How can I record that time?

I need this in order to display in the user interface the time difference between the click time on the submit button and when the result is returned.

You can do something like this

t1 <- Sys.time()

# long script goes here

t2 <- Sys.time()
t_diff <- t2 - t1
#> Time difference of 10.01269 secs

I know that but I want to do that inside a shiny application.

I would like to know how to record that inside the shiny code

Just put the code inside the observeEvent() for the button


ui <- basicPage(
    actionButton("submit", "Submit"),

server <- function(input, output, session) {
    observeEvent(input$submit, {
        t1 <- Sys.time()
        # long script goes here
        t2 <- Sys.time()
        output$text <- renderText({
            paste("The long script took", round(t2 - t1, 2), "seconds to complete") 

shinyApp(ui, server)

There is also small package called tictoc that does very similar thing with more bells and whistles.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.