For the best performance, I would use a server side cache to store the shared data (unless the data is very small). Each callback would then access this cache and send only the needed data to the client.
The data is just 1260 rows one column and the index (dates) for the last share price closed from the last five years, I supposed that is a small (but I don’t know if its “very small” ).
I saw your solution to use serving side caching, it looks pretty interesting, but I didn’t try to implement yet.
Related to using multiple callback versus using one to issues that are related each other, do you have an opinion? I read in the documentation that each callback spend additional time but I cant figure out if this time is compensated for using them in parallel.
I had a similar performance problem where I had multiple charts based on the same shared 100 days of Daily OHLC stock data.
I resolved it by having one callback that loads the data from the source data API into a dcc.Store object with storage type of Memory, which stores the ‘shared’ data, and then the individual chart call backs load the shared data from the dcc.Store object. I found the dcc.Store to work efficiently for this purpose as it eliminated the need to make multiple API requests for the same data.
If you are using dcc.Store let implement server side caching callback, it’s very easy to do because use the same dcc.Store and you only need to make two minor changes in your code, just import the library:
from dash_extensions.enrich import Dash, ServersideOutput, Output, Input, State, Trigger
And replace the Output to the dcc.Store with:
ServersideOutput(
It uses the same Inputs, and manage all the info in the server side.
Thanks for the great tip @Eduardo. I also had to modify app = dash.Dash()… to app = Dash() to get it working. This had an incremental improvement as the data then avoided the round trip and my files are relatively small, but the thing that really made the difference for my app was that where before I was using the Clientside Store Output that only supports JSON and thus had to the convert the data objects from/to JSON in the beginning/end of each callback, that step is no longer necessary with the ServersideOuput and even with small data loads I saw a huge improvement. Thanks again to you and @Emil.