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.

figure as state out of sync

See original GitHub issue

In this simple app from @emmanuelle, figure.layout.shapes doesn’t seem to be updated when figure is captured as State, meaning that we have to do all sorts of gymnastics with relayoutData to work with shapes.

@alexcjohnson can you help me figure out if this is something in dcc or if Plotly.js is doing something odd here, in which case help me translate this into a CodePen that @archmoj can use?

import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objects as go
from dash.dependencies import Input, Output, State
import dash
import json

app = dash.Dash(__name__)

fig = go.Figure().update_layout(dragmode='drawrect')

app.layout = html.Div([
    dcc.Graph(id='graph', figure=fig),
    html.Pre(id='annotations-data'),
])

@app.callback(
    Output('annotations-data', 'children'),
    [Input("graph", "relayoutData")],
    [State("graph", "figure")]
)
def on_new_annotation(relayout_data, fig):
    return json.dumps(go.Figure(fig).layout.shapes, indent=2)

app.run_server(debug=True)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
emmanuellecommented, Dec 1, 2020

@almarklein, @nicolaskruchten mentioned that https://github.com/plotly/dash-core-components/issues/584 targets the same piece of the dcc code so that it could be interesting to target the two issues together.

0reactions
dellacortelabcommented, Jun 22, 2022

I am running into related issues with a callback that Outputs a figure and loads the figure from a State. Many of deeper attributes, like line_colors of traces or _grid_ref are set to None in the figure dictionary received from State.

I had to use various hacks, like creating empty figures with subplot grids or storing color information in store objects and adding them back in annoying for-loops over the traces.

Is it somehow possible to return a “deep dictionary” of a figure that retains attributes currently lost?

I am using Dash 2.5.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux: Can't figure out why ownProps gets out of sync with state
Problem. In ConnectedList , state.listItems was not empty, so List renders an instance of ConnectedListItem . However, state.
Read more >
Don't Sync State. Derive It! - Kent C. Dodds
Let's find out the benefits of derived state over state synchronization by reimplementing this with a more naive approach.
Read more >
How to Fix Out of Sync Audio and Video in Windows 10
1. Try These Easy Solutions · 2. Run the Audio Troubleshooter · 3. Check Speaker Properties · 4 . Restore Default Settings for...
Read more >
Out of sync Definition & Meaning - Merriam-Webster
in a state in which two or more people or things do not move or happen together at the same time and speed....
Read more >
SyncChecker: Detecting Synchronization Errors between MPI ...
out corrupted message data or reading undefined message data. ... Figure 3 shows the state machine for detecting synchronization errors.
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