dash icon indicating copy to clipboard operation
dash copied to clipboard

[BUG] When changing content of dcc.graph from one with locked axes ratio, to another with different axis domain, the domain is not updated.

Open tlauli opened this issue 3 years ago • 1 comments

Environment

dash                      2.4.1
dash-core-components      2.0.0
dash-html-components      2.0.0
dash-table                5.0.0
plotly                    5.8.0
  • OS: Arch linux
  • Browser: Chromium
  • Version 102.0.5005.61 (Official Build) Arch Linux (64-bit)

Describe the bug

MWE:

from dash import Input, Output, Dash, html, dcc
import plotly.graph_objects as go


app = Dash(__name__)

app.layout = html.Div(
    [
        dcc.Dropdown(id="dropdown", value="1", options=["1", "2", "3"]),
        dcc.Graph(id="plot", style={"height": "85vh"}),
    ],
)


def get_graph_1():
    layout = {"xaxis": {}, "yaxis": {"scaleanchor": "x", "scaleratio": 1}}
    fig = go.Figure(layout=layout)
    fig.add_trace(go.Scatter(x=[0, 1, 2], y=[0, 1, 0]))
    return fig


def get_graph_2():
    layout = {"xaxis": {}, "yaxis": {"domain": [0.0, 0.5]}}
    fig = go.Figure(layout=layout)
    fig.add_trace(go.Scatter(x=[0, 1, 2], y=[1, 0, 1]))
    return fig


@app.callback(
    Output("plot", "figure"),
    Input("dropdown", "value"),
)
def dnum_cb(val):
    if val == "1":
        return get_graph_1()
    else:
        return get_graph_2()


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

When changing graph from one with locked axes ratio, to another with different axis domain, the domain is not updated. Steps to reproduce:

  • Run the MWE server (screenshot 1).
  • Switch dropdown from value "1" to value "2".
  • Observe that y axis domain has not updated (screenshot 2).
  • Switch dropdown from value "2" to value "3".
  • Observe that domain has updated, even though the same graph was returned in the callback (screenshot 3).

Expected behavior

The axis domain is correctly updated regardless of previous dcc.Graph content.

Screenshots Screenshot 1: newplot Screenshot 2: newplot (3) Screenshot 3: newplot (4)

tlauli avatar Jun 06 '22 09:06 tlauli

Thanks @tlauli - I can confirm the bug, and I was surprised to see that the issue seems to be specific to Dash, it doesn't happen in plain plotly.js - see https://codepen.io/alexcjohnson/pen/wvGvREO?editors=0010, click react @ step 0 then react @ step 1 and the domain is correct. Will take a bit more investigation...

alexcjohnson avatar Jun 08 '22 13:06 alexcjohnson