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?
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:
Seems somewhat basic, is there really no way to update only some traces in a figure supported officially?
Is there a way to up vote a request for such a feature?
This is great! I used this approach to sync a playhead (vertical line) on my graph with an audio file played via dash_player.
@callback(
Output('graph-content', 'figure'),
Input('audio-player', 'currentTime'),
State('graph-content', 'figure')
)
def update_graph(current_time: float | int, figure: dict | None):
if figure is None:
# Used to add figure elements on the first callback only
first_fig = px.scatter(points, x='time', y=['SPEAKER_00', 'SPEAKER_01'])
first_fig.add_vline(x=current_time, line_width=3, name='playhead')
return first_fig
# If the scatter plot has been drawn, only update the vertical line
figure['layout']['shapes'][0]['x0'] = current_time
figure['layout']['shapes'][0]['x1'] = current_time
return figure```