Show preselected data points on a scatter plot in dash

Hi,

Is it possible to draw a scatter plot using dcc.Graph that highlights selected data points saved from a previous session, while still showing all the possible data points ?

I tried by passing the saved selectedData to dcc.Graph at first first but then read it is read-only so it doesn’t update the scatter plot.

i.e. get back this graph on subsequent sessions:

Any suggestions?

Hi @mac0, I think your question is similar to Set selecteddata programatically. In a nutshell, selectedData is read-only but selectedpoints is read/write. An example is given in the “Generic Crossfilter Recipe” example of https://dash.plot.ly/interactive-graphing.

Thank you very much @Emmanuelle , I could make it work, at least partially. I have a callback that is triggered by selectData. Although my graph now shows the previously selected data using selectedpoints, the callback is not triggered. selectDatais None. Also, if i want to select more points, by holding the SHIFT key, the previous selection is overwritten.

Is there a way to achieve what I need?

for the callback, can’t you have selectedpoints as an additional Input of your callback?

yes I can do that for the callback. I am not sure how to solve the SHIFT key problem or how to “unselect” a previously selected point (coming from a dcc.Store). At the moment, the plot is drawn fine but when clicking on a “selected” point, it select it again.

Related is this issue - https://github.com/plotly/plotly.js/issues/1851, which I believe would solve this without workarounds - handling not just the points that are selected, but also the region / bounding box.

is this solved somehow? when I set selectedpoints as an output of a callback, the points are selected on the graph(they are highlighted) but selectedData remain null until I manually select something and then it overwrites what was set by selectedpoints. Im also not sure how to read selectedpoints (how to put it as an Input into a callback).