✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Only update some traces in graph

Hi,

I have a graph with a lot of data, then I add three horizontal lines to view a kind of threshold which can be adjusted by changing the input value of an input box.

The graph itself looks like on the attached picture

When I update to the input value to adjust the thresholds(which is just a line between two datasets), the whole graph have to be updated which takes a couple of seconds.

Is it possible to only update the three lines so the rest of the data stays unchanged and doesn’t need to be update?

yes it is possible.
Just give visibility= True,
or Visibility = legendonly

Just look at the plotly documentation https://plot.ly/javascript/reference/#scatter-visible

I don’t think this answers my question…
Because all 4 legends should be visible, I just only want to update 3 of them. The 4’th should somehow be static.

Any updates on this? I have a vertical bar I want to update like OP but I want the data to stay static (most of the time). The performance is horrific since I update the whole figure every time. Can I update the single trace and prevent the performance hit associated with drawing 6000 points?

I have a temporary solution. I found this custom dash component: mydcc from https://github.com/jimmybow/mydcc. He has developed a ChangeTrace dash component to update plotly graph trace (only for graph with one trace).
You can install it with:

pip install mydcc

But, the problem is if you have multiples traces in the graph that component won’t work properly. I changed the code of him a little bit to support multiple traces. But, my version needs all the traces in a list to be updated (traces with new data and traces with old data):

You can try it and see if this temporary solution is suitable for you. The good thing with this is that you don’t need to re-draw the graph again, just all the data in the graph. It will be much faster. In the future a could try a way to set a option to delete a specific trace and then, change its content something like:

fig['data][trace to modify]=new data

2 Likes