How to improve load time and responsiveness for html page with plotly chart created with R Markdown?

I’ve created an html page with R Markdown and contain a plotly box plot but it loads slowly and tends to freeze while scrolling. Since I’m new to using plotly I am not sure where to look to make improvements. The page itself is only 3.57MB and has a plotly box plot and ggplot based bar graphs. I had initially render the bar graphs with ggplotly but the performance was really bad - made firefox crash. Any tips on where I could look to make improvements?

The page is located here: http://rpubs.com/mihiriyer/crisis
The code is on github: https://github.com/mihiriyer/crisis

Don’t use plotly enough to be helpful here, I pinged Carson on Twitter…

I built the pub and used ggplotly to plot your bar charts with plotly. It seems ok to me.

I posted it to rpubs here:
http://rpubs.com/bhive01/plotlytest

I will admit that it does slow down when I get to the plots, but it’s not making Chrome crash.

I’m OS X 10.11.4, Chrome 50.0.2661.66 beta (64-bit)

devtools::session_info()
Session info ---------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.4 (2016-03-10)
 system   x86_64, darwin13.4.0        
 ui       RStudio (0.99.892)          
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2016-04-29                  

Packages -------------------------------------------------------------------------------------------------------------------
 package      * version     date       source                               
 assertthat     0.1         2013-12-06 CRAN (R 3.2.0)                       
 base64enc      0.1-3       2015-07-28 CRAN (R 3.2.0)                       
 colorspace     1.2-6       2015-03-11 CRAN (R 3.2.0)                       
 DBI            0.3.1       2014-09-24 CRAN (R 3.2.0)                       
 devtools       1.11.1.9000 2016-04-29 Github (hadley/devtools@fe27701)     
 digest         0.6.9       2016-01-08 CRAN (R 3.2.3)                       
 dplyr          0.4.3.9001  2016-04-29 Github (hadley/dplyr@5e2b40e)        
 ggplot2      * 2.1.0       2016-03-01 CRAN (R 3.2.4)                       
 gridExtra      2.2.1       2016-02-29 CRAN (R 3.2.4)                       
 gtable         0.2.0.9000  2016-02-26 Github (hadley/gtable@0ed36a4)       
 htmltools      0.3.5       2016-03-21 CRAN (R 3.2.4)                       
 htmlwidgets    0.6.1       2016-04-29 Github (ramnathv/htmlwidgets@8d01646)
 httr           1.1.0       2016-01-28 CRAN (R 3.2.3)                       
 jsonlite     * 0.9.19      2015-11-28 CRAN (R 3.2.2)                       
 knitr          1.12.3      2016-01-22 CRAN (R 3.2.3)                       
 lazyeval       0.1.10.9000 2016-04-29 Github (hadley/lazyeval@bce211b)     
 lubridate    * 1.3.3       2013-12-31 CRAN (R 3.2.0)                       
 magrittr       1.5         2014-11-22 CRAN (R 3.2.0)                       
 memoise        1.0.0       2016-01-29 CRAN (R 3.2.3)                       
 munsell        0.4.3       2016-02-13 CRAN (R 3.2.3)                       
 plotly       * 3.5.1       2016-04-29 Github (ropensci/plotly@5e0ad36)     
 plyr           1.8.3.9000  2015-10-16 Github (hadley/plyr@9d8294e)         
 R6             2.1.2       2016-01-26 CRAN (R 3.2.3)                       
 RColorBrewer * 1.1-2       2014-12-07 CRAN (R 3.2.0)                       
 Rcpp           0.12.4      2016-03-26 CRAN (R 3.2.4)                       
 rmarkdown      0.9.5       2016-02-22 CRAN (R 3.2.3)                       
 rsconnect      0.4.1.11    2016-04-29 Github (rstudio/rsconnect@202c93b)   
 scales         0.4.0.9000  2016-02-26 Github (hadley/scales@646b6a4)       
 stringi        1.0-1       2015-10-22 CRAN (R 3.2.0)                       
 stringr        1.0.0       2015-04-30 CRAN (R 3.2.0)                       
 tibble         1.0-1       2016-04-01 Github (hadley/tibble@cb38672)       
 tidyr          0.4.1.9000  2016-04-29 Github (hadley/tidyr@c889f4a)        
 viridis        0.3.4       2016-04-07 Github (sjmgarnier/viridis@e48e9c0)  
 withr          1.0.1       2016-02-04 CRAN (R 3.2.3)                       
 yaml           2.1.13      2014-06-12 CRAN (R 3.2.0) 

The box trace type in plotly.js currently requires the entire distribution of data to be sent to the browser, which is likely the bottleneck here. You can track this issue to follow progress on this front https://github.com/plotly/plotly.js/issues/242

In the meantime, you might consider using something like geom_violin() instead

3 Likes

@cpsievert - that makes sense, the data set I’m using is rather large 190MB (68 variables & 370K observations).

Thanks for the tips Everybody!

1 Like