Issue in capturing the r code execution time

I am planning to capture the execution of R code in my shiny application that is deployed on shiny server pro.

library(shiny)

ui <- fluidPage(
  ### ui code
)

server <- function(input, output, session) {
  start_time <- Sys.time()
  
  ### server code
  
  end_time <- Sys.time()
  
  speed <- end_time - start_time
  
  if(file.exists("Speed.csv")){
    write.table(speed,  
                file="./Speed.csv", 
                append = T, 
                sep=',', 
                row.names=T, 
                col.names=F )
  } else {
    write.csv(speed, "Speed.csv")
  }
  
}

shinyApp(ui, server)

if you see above i have sys.time() at the first and at the last. THen I am saving/appending to csv file.

I see some big issue here. When the csv is generated here, it shows 0.5 secs. But when I checked manually with stop watch, it is showing me around 18 secs execution time (the time the plots and tables are displayed on screen).

Why is this happening???? There is big difference between 0.5 secs and 18 secs.

One possibility is, 0.5 secs is correct, But the time it is taking to display the plots and tables is taking time.

Can anyone guide me?

A point to consider is that after the server has executed your code, the result still has to be transferred to the client over the network and the client's browser has to render it so your waiting time is going to be affected by your network performance and the available processing power of the client's computer. Having said that, such amount of lag is not normal so you might want to check for technical issues.

Thanks for this.

But what you mean by technical issues?? Can you provide some ideas?

I mean technical issues with your network, the user computer or the configuration of both, It is hard to give you specific ideas since this sort of problems are very system specific and you are not providing much relevant information but maybe "operations" people with experience managing shiny-server in complex environments might be able to give you some frequent points of failure to check.

This topic was automatically closed 54 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.