Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Dont clone figure.layout#905

Merged
alexcjohnson merged 16 commits intoplotly:devfrom
almarklein:figure-state
Jan 15, 2021
Merged

Dont clone figure.layout#905
alexcjohnson merged 16 commits intoplotly:devfrom
almarklein:figure-state

Conversation

@almarklein
Copy link
Contributor

@almarklein almarklein commented Dec 14, 2020

Fixes #879 (hopefully)

This small changes fixes the issue (for e.g. the example below). That said, I cannot oversee whether this potentially breaks other code. In theory, the tests will tell ;)

Example to test this:

import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output, State


app = dash.Dash(__name__, update_title=None)

fig = {"data": [], "layout": {"dragmode": "drawrect"}}
graph = dcc.Graph(id="graph", figure=fig)

app.layout = html.Div(
    [
        graph,
        html.Br(),
        html.Button(id='button', children="Clone figure"),
        html.Div(id='output', children=""),
    ]
)

app.clientside_callback(
    """function clone_figure(_, figure) {
        let new_figure = {...figure};
        let shapes = new_figure.layout.shapes || [];
        return [new_figure, shapes.length];
    }
    """,
    [Output("graph", "figure"), Output("output", "children")],
    [Input("button", "n_clicks")],
    [State("graph", "figure")],
)



if __name__ == "__main__":
    app.run_server(debug=True)

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

figure as state out of sync

3 participants