plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.11k stars 2.04k forks source link

[BUG] scattermapbox traces do not update correctly when the figure template changes as of dash 2.7.0 #2343

Closed AnnMarieW closed 1 year ago

AnnMarieW commented 1 year ago

As of dash 2.7.0, px.scatter_mapbox traces do not update when the figure template is changed.

It might have something to do with this change?

Feature release 2.16.0 adds clustering to scattermapbox traces and restricted bounds to mapbox plots.

For example, in dash dash 2.6.2 it works correctly: mapbox-dash-2 6 2

In dash 2.7.0, the traces are not updated but the legend and the hover info is correct for each template.

mapbox-dash2 7 0

from dash import Dash, dcc, html, Input, Output
import plotly.express as px
import dash_bootstrap_components as dbc

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

carshare = px.data.carshare()

figure_templates = [
    "plotly",
    "ggplot2",
    "seaborn",
    "simple_white",
    "plotly_white",
    "plotly_dark",
    "presentation",
    "xgridoff",
    "ygridoff",
    "gridon",
    "none",
]

change_figure_template = html.Div(
    [
        html.Div("Change Figure Template"),
        dcc.Dropdown(figure_templates, figure_templates[0], id="template"),
    ],
    className="pb-4",
)

app.layout = dbc.Container(
    [
        dbc.Row(dbc.Col(change_figure_template, lg=6)),
        dbc.Row(dbc.Col(html.Div(id="graphs"))),
    ],
    className="dbc p-4",
    fluid=True,
)

@app.callback(
    Output("graphs", "children"),
    Input("template", "value"),
)
def update_graph_theme(template):

    return dcc.Graph(
        figure=px.scatter_mapbox(
            carshare,
            lat="centroid_lat",
            lon="centroid_lon",
            color="peak_hour",
            size="car_hours",
            size_max=15,
            zoom=10,
            mapbox_style="carto-positron",
            title=f"Carshare <br> {template} figure template",
            template=template,
        ),
        className="border",
    )

if __name__ == "__main__":
    app.run_server(debug=True)
archmoj commented 1 year ago

Thanks for the report. Regression confirmed: https://github.com/plotly/plotly.js/issues/6382

rodrigoalatorre commented 1 year ago

I've found a simmilar issue with graph_objects.Scattermapbox using 2.7.0

archmoj commented 1 year ago

This bug is addressed by https://github.com/plotly/plotly.js/releases/tag/v2.16.4. Until next dash release you could provide plotly.js bundle in the asset folder to have the fix.

ned2 commented 1 year ago

@AnnMarieW can confirm that your example is now working with Dash 2.7.1, which includes the Plotly 2.16.4 🎉