Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

plot_ly performance within shiny

I am analyzing the speed of my shiny app with profvis.
I have noticed that one of my simple calls to plot_ly takes 2500 ms, but when I make the same call in a R console environment it is less than 10 ms. Do you have any idea what the problem is here and what can be done to solve it?

I do not know about Shiny, but I am using Flask and SocketIO to create a similar behavior in Python, and I noticed the same performance issue.

On Python, it is coming from the fact that Plotly serialize data frames to JSON to produce the plot, and it is very very slow for several reasons. First, they use the standard library json library, which is much slower than others. Second, they implement a custom class to serialize all sorts of data (dataframe, datetime, series, objects, etc…) and they use duck-typing, which further slows the serialization process.

I hope they will implement better serialization in future updates: as of now, the library is extremely slow on large datasets…