Retain clicked data when the plot is updated


I have been trying to put a dash app together that is plotting a scatter plot. And the plot keeps updating as data changes in the database. One thing I couldn’t figure out is if a point of the plot is clicked and the plot updates due to updated data, how can I retain the clicked point after the plot updates? When I return the figure dictionary, the whole plot re-renders. Any thoughts?

Hi @cknatarajan welcome to the forum! You can use a dcc.Store which is updated when the clickData property of your graph changes, and add the new clicked data to the dcc.Store. See for the documentation of dcc.Store.

Thank you @Emmanuelle! That is an interesting idea. But when i was reading up on clickData and it seems like it is a readonly property:

clickData ( dict ; optional): Data from latest click event. Read-only.

Can i set clickData as an Output of the callback? I am going to test it but I wanted to make sure if this will work.

Yeah @Emmanuelle I just tested it out, and I cannot set the clickData property.

Have you tried the uirevision property?

I was suggesting to use the clickData as input and to store these data somewhere else like in a dcc.Store. Why would you need to update clickData as well? It is indeed read only.

Thank you @Emmanuelle, I should have clarified that I needed the clicked data to be retained and reflected on the plot after the plot updates.

@Emil - that’s a great suggestion but I couldn’t figure out activating uirevision based on multiple inputs - I have a data update callback that should retain the plot state but with other callback inputs it should update. Any help to figure that out is greatly appreciated.

@cknatarajan - As i understand, the uirevision property work in a such way that the graph is “reset” (zoom etc.) only when the UI revision changes. Hence if you have inputs [a,b,c,d] and the graph should only be reset when a or b changes, you should set the uirevision based on (a,b), e.g. to something like hash(a,b) or json.dumps(dict(a=a, b=b)).

@Emil - Thanks so much, this worked perfectly. Actually the json implementation worked! Really cool stuff, thanks for the help.