Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotly selection state is lost when re-rendering. #147

Open
DylanVann opened this issue May 31, 2019 · 12 comments
Open

Plotly selection state is lost when re-rendering. #147

DylanVann opened this issue May 31, 2019 · 12 comments

Comments

@DylanVann
Copy link

@DylanVann DylanVann commented May 31, 2019

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

selection

How it behaves when not re-rendering (selection box is maintained):

better-selection

@DylanVann DylanVann changed the title Plotly state is lost when re-rendering. Plotly selection state is lost when re-rendering. May 31, 2019
@nicolaskruchten
Copy link
Member

@nicolaskruchten nicolaskruchten commented May 31, 2019

You should be able to use uirevision to avoid most such problems: https://plot.ly/javascript/uirevision/

@DylanVann
Copy link
Author

@DylanVann DylanVann commented May 31, 2019

It does not seem to work for selection state.

@nicolaskruchten
Copy link
Member

@nicolaskruchten nicolaskruchten commented May 31, 2019

In your codepen, what does the problem look like? Can you post a gif? I can't replicate any issues on this end...

@DylanVann
Copy link
Author

@DylanVann DylanVann commented May 31, 2019

Posted a couple gifs in the description.

@nicolaskruchten
Copy link
Member

@nicolaskruchten nicolaskruchten commented Jun 1, 2019

Oh I see, the selection box disappears. Yes, this is not something which is persistent in plotly.js at the moment (it's not part of the figure spec at all actually) ... issue: plotly/plotly.js#1851

@DylanVann
Copy link
Author

@DylanVann DylanVann commented Jun 5, 2019

Cool. Ideally to fit React's model selection could even be a controlled prop.

@nicolaskruchten
Copy link
Member

@nicolaskruchten nicolaskruchten commented Jun 6, 2019

Yes, this would be ideal but the underlying Plotly.js library doesn't really work in such a way as to be compatible with this. The idea behind uirevision is for it to be more controllably uncontrolled :)

@Kiiiwiii
Copy link

@Kiiiwiii Kiiiwiii commented Jun 21, 2019

@DylanVann you can control the constraint-range + range + selectedpoints property of traces to maintain the select state yourself, but it takes a lot of time. The api is not programmer-friendly

@will-moore
Copy link

@will-moore will-moore commented Feb 22, 2020

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:

Component = () => {
    const [selectedIds, setSelectdIds] = React.useState([]);

    return (
        <div>
            <PlotContainer setSelectdIds={setSelectdIds} />
            <ShowSelected selectedIds={selectedIds} />
        </div>
    )

Any pointers or workarounds would be much appreciated? Thanks.

@will-moore
Copy link

@will-moore will-moore commented Feb 23, 2020

Actually, I re-read the issue above and realise that was really concerned about the selection box but I'm not too bothered about the box. For me, I lose the selection itself. Is there a way to preserve the selected points? I've used all the state management described at https://github.com/plotly/react-plotly.js#state-management to preserve the axis ranges etc but I don't see selected objects in any of that state?

@matthias-ccri
Copy link

@matthias-ccri matthias-ccri commented Feb 28, 2020

It would be good to get the selection as an input props. I was hoping to use react-plotly. I'm implementing something like crossfilter where the plot selections/brushes are a key part of the interface.

However it sounds like the underlying plotly library doesn't have robust selection support. Is there some workaround, so I can use react-plotly instead of d3? — maybe overlaying my own selection box outside of plotly, but then it would have to synchronize with the margins and scales.

@will-moore
Copy link

@will-moore will-moore commented Mar 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.