react-plotly.js: Plotly selection state is lost when re-rendering.
This codepen shows the issue: https://codepen.io/dylanvann/pen/OYaedz
The onHover
handler forces a re-render.
Whenever the Plot is re-rendered some state is lost. In particular the selection is lost.
How it behaves when re-rendering (selection box is not maintained):
How it behaves when not re-rendering (selection box is maintained):
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 17 (4 by maintainers)
I’m using Plotly with crossfilter, and it seems that sometimes I am losing the current selection because of a re-render and sometimes not. Haven’t got to the bottom of it yet… https://github.com/will-moore/parade-crossfilter/blob/master/src/plots/Plot.js is my wrapper to maintain axis ranges on re-render. The parent https://github.com/will-moore/parade-crossfilter/blob/master/src/plots/ScatterPlot.js listens for when the crossfilter filter changes to update the plot. Based on React-crossfilter example at https://www.lighttag.io/blog/react-dc-js/.
Just ran into this issue myself. When I drag to select a region on the scatter plot, I want to show the selected items so I’m using
onSelected
to update the selected IDs in a parent Component. But unfortunately this state change is causing the<Plot/>
inside the<PlotContainer />
to re-render and so I don’t see the selection change in the Plot:Any pointers or workarounds would be much appreciated? Thanks.
Cool. Ideally to fit React’s model selection could even be a controlled prop.