# Show preselected data points on a scatter plot in dash

**URL:** <https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980>\
**Category:** Dash Python\
**Created:** [March 9, 2020, 11:26am UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980 "2020-03-09T11:26:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mac0](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mac0](https://community.plotly.com/u/mac0)\
**Post date:** [March 9, 2020, 11:26am UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/1 "2020-03-09T11:26:11Z")

</div>

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:

 ![selection-scatter](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/4/45957c1ec4b41ac4ba1d4dd31f6aebf22a9b4176.png)

Any suggestions?

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [March 9, 2020, 9:33pm UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/2 "2020-03-09T21:33:42Z")

</div>

Hi @mac0, I think your question is similar to [Set selecteddata programatically](https://community.plotly.com/t/set-selecteddata-programatically/18759). 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](https://dash.plot.ly/interactive-graphing).

---

<div class="post-metadata">

**Author:** ![mac0](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mac0](https://community.plotly.com/u/mac0)\
**Post date:** [March 10, 2020, 3:09pm UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/3 "2020-03-10T15:09:31Z")

</div>

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. `selectData`is `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?

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [March 10, 2020, 3:30pm UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/4 "2020-03-10T15:30:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mac0](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mac0](https://community.plotly.com/u/mac0)\
**Post date:** [March 10, 2020, 3:53pm UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/5 "2020-03-10T15:53:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [March 10, 2020, 5:01pm UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/6 "2020-03-10T17:01:10Z")

</div>

Related is this issue - [https://github.com/plotly/plotly.js/issues/1851](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.

---

<div class="post-metadata">

**Author:** ![Dano](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@Dano](https://community.plotly.com/u/Dano)\
**Post date:** [January 27, 2024, 10:33am UTC](https://community.plotly.com/t/show-preselected-data-points-on-a-scatter-plot-in-dash/35980/7 "2024-01-27T10:33:02Z")

</div>

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).
