Shiny (R) Web App Performance – Profiling

[This article was first published on r - read and write, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Introduced at the 2016 R conference, the profvis package offers a visual way of inspecting the call stack and highlights the most memory and computationally intensive parts of your code.

Run Profvis

# Load library
library(profvis)

# Run profiler on shiny app with optional arg to save output
profvis({ runApp('Projects/path_of_app') }  
        , prof_output = '/path_to_save_output')

At this point your app will launch, to get the shiny app code to execute, interact with the parts of the application that you are interested in. Once you have completed the interactions, close the page and press the ‘stop’ button at the top of the console in RStudio. Profvis will recognise you have stopped running the shiny app, display the profvis interface and optionally save the file. The file name is randomly generated and should look something like this file108f93bff877b.Rprof.

Each block in the flame graph represents a call to a function, or possibly multiple calls to the same function. The width of the block is proportional to the amount of time spent in that function. When a function calls another function, another block is added on top of it in the flame graph.

Source: Profvis Overview

To reload the saved profvis profile:

# Load saved profvis
profvis(prof_input = '/path_to_save_output/file108f93bff877b.Rprof')  

Reload a Saved Profvis

You can also save as a webpage using the following code:

# Assign to variable
p <- profvis(prof_input = '/path_to_save_output/file108f93bff877b.Rprof')

# Save as a webpage
htmlwidgets::saveWidget(p, "/path_to_save_output/profile.html")  

Resources

To leave a comment for the author, please follow the link and comment on their blog: r - read and write.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)