Code profiling for Shiny app?

前端 未结 3 1672
谎友^
谎友^ 2020-12-29 05:31

For an R Shiny web app, what are some good ways to run code profiling that show the parts of the Shiny code that are taking the most processing time?

I\'ve got a bi

3条回答
  •  忘掉有多难
    2020-12-29 06:12

    I think this question needs a little update, therefore I am adding another answer to it...

    You can use the package profvis to profile shiny apps as well. It will give flame graphs directly for your R code. I.e. no need to use Chrome's flame graphs and guess where the bottleneck is. You will know exactly where to change your code.

    Here is how to do it:

    1. Run shiny app via Profvis
    2. Interact with your shiny app
    3. Close browser
    4. Stop Console via Stop button
    5. Load profile
    6. If Step 5 fails, try this: Convert to html if needed (memory problems)

    Details for certain steps are added below:

    Step 1: Run profvis

    library(profvis)
    profvis({ runApp('directory_of_shiny_app') }  
        , prof_output = '/directory_to_save_profile')
    

    Step 5: Load your profile

    profvis(prof_input = '/path_to_save_output/random_name.Rprof') 
    

    N.B. Profvis gives a random name to your file. So you need to change the input path accordingly

    Step 6: Convert to html

    This step might be needed, if you have a huge app and flame graph gets a little bit longer. You might get an error "Pandoc:... memory"

    p <- profvis(prof_input = '/path_to_save_output/file108f93bff877b.Rprof')
    htmlwidgets::saveWidget(p, "/path_to_save_output/profile.html")
    

    Then open the html file in your browser.

提交回复
热议问题