Profiling Shiny apps in RStudio for more than 30 seconds?

Using RStudio 1.2.5001 and R 3.6.3 on RedHat 7, I have a Shiny app in an app.R file where the last line is shinyApp(ui = ui, server = server).

When I click "Profile=>Start Profiling" and then click "Run App" in the RStudio IDE, my app starts up. It takes

  • 5 seconds to load and pop open the web browser,
  • 23 seconds before all the widgets with the spinners to display via addSpinner(plotlyOutput(... calls
  • 108 seconds before the plotlyOutput completes and the widgets display the plots. I then click Profile=>Stop Profiling and the profile with the flame graph appears.

However, the flame graph only shows data for a timeline of around 30 seconds.

So the bulk of the time I am unable to profile.

I have tried using profvis other ways in the RStudio IDE without success. If I wrap the entire file in profvis({ and }) I get the error

Error in func(fname, ...) : app.R did not return a shiny.appobj object. 

and if I add runApp(shinyApp(ui = ui, server = server)) at the bottom I get the error

Can't call `runApp()` from within `runApp()`.

What is the recommended way to profile a Shiny app in this situation? Should I try using profvis outside of the RStudio IDE? Is there another way to use profvis? Or is this a known bug or limitation of profvis or of RStudio 1.2.5001?

Even when I profile using profvis without , using the default 10ms, the header of the created Rprof file includes sample.interval=10000 which presumably is microseconds, as the default interval is supposed to be 10ms, and only 4366 lines, even after running for 2+ minutes, so 10ms*4366 is around 43 seconds worth of profiling information.

I would experiment with stopping the app being profiled first, and only then stop the profiler as a final step.