question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plotly selection state is lost when re-rendering.

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
will-moorecommented, 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/.

1reaction
will-moorecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plot does not re-render on state change
I have a component that changes view from line plot to table on checkbox change. Checkbox is handled through state: handleCheckbox = e...
Read more >
How do I integrate Plotly realtime updating graphs with React ...
Plotly graphs have an update function that makes it so the entire graph isn't destroyed/rerendered. So I have a few questions. 1. Is...
Read more >
A plotly.js React component from Plotly
This is a "dumb" component that doesn't merge its internal state with any updates. This means that if a user interacts with the...
Read more >
holoviews.plotly Package
Refreshes the plot by rerendering it and then pushing the updated data if the plot has an associated Comm. set_root(root)#. Sets the root...
Read more >
A Plotly.js React Component From Plotly - Morioh
datarevision are used to force a rerender. API Reference. Basic Props. Warning: for the time being, this component may mutate its layout and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found