Adding custom url style to Scattermapbox causes callbacks to not update the figure

Hi!
I am trying to use go.Scattermapbox to create a interactive map where buttons can change marker colors on the map.
It works fine until I try to set a custom mapbox style URL to the layout.mapbox.style attribute.
I tried multiple different urls, and I can see the desired style on my map, but callbacks no longer do anything, even though I can see that they output the right thing, the map just won’t update.

Here is an example:

from dash import Dash, dcc, Input, Output, State, no_update
import dash_bootstrap_components as dbc
import plotly.graph_objects as go


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

figure = go.Figure(
    data=go.Scattermapbox(
        lat=[45.5017],
        lon=[-73.5673],
        mode='markers',
        marker=go.scattermapbox.Marker(
            size=14, color="red"
        ),
    ),
    layout=go.Layout(
        mapbox=dict(
            accesstoken="pk.eyJ1IjoidGNoYXJsYW5kMTMiLCJhIjoiY2t2bHRtbHp2MDRpeDJwbW56bXRmamhwMiJ9.zSInHNf-s7bQDqHmJLchIA",
            style="mapbox://styles/tcharland13/cllia1yqn021601qm6u6ihnv2", # Removing this line makes it work
            center=dict(
                lat=45,
                lon=-73
            ),
        ),
    ),
)

app.layout = dbc.Container([
    dcc.Graph(id="map", figure=figure),
    dbc.Button("Click me", id="button"),
], fluid=True)


@app.callback(Output("map", "figure"),
              Input("button", "n_clicks"),
              State("map", "figure"))
def update_map(n_clicks, figure):
    if not n_clicks:
        return no_update
    figure["data"][0]["marker"]["color"] = "blue" if n_clicks % 2 else "red"
    return figure

if __name__ == '__main__':
    app.run_server(debug=True, port=8054)

I am running

dash==2.12.1
plotly==5.16.1

Thanks!

Hey @tcharland13, so your code worked just fine when I ran it with dash == 2.5.1 and plotly == 5.5.0

Then I upgraded both libraries and it stopped working…

1 Like

Thank you for the solution!