Skip to content

[BUG] Dynamic update of Mapbox style not working #1152

Description

@bluenote10

Context
Please provide us your environment so we can easily reproduce the issue.

  • pip list | grep dash
dash                               1.9.1               
dash-bootstrap-components          0.9.1               
dash-core-components               1.8.1               
dash-html-components               1.0.2               
dash-renderer                      1.2.4               
dash-table                         4.6.1               
  • Browser versions (but most likely not a frontend issue):

    • OS: Ubuntu 16.04
    • Browser: Firefox
    • Version: 73.0.1

Describe the bug

I have a use case which requires to dynamically set the style of a Mapbox map, for instance to modify the underlying tile server. It looks like dynamic updates of mapbox styles do not lead to an update of the map. Minimal reproducing example:

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

import plotly.graph_objects as go


def init_app():
    app = dash.Dash(__name__)

    graph = dcc.Graph(
        id='graph',
        style={
            'width': '100%',
            'height': '1000px',
        }
    )
    switch = dcc.RadioItems(
        id='switch',
        options=[
            {'label': 'Map A', 'value': 'A'},
            {'label': 'Map B', 'value': 'B'},
        ],
        value='A',
    )
    app.layout = html.Div(children=[
        html.Div(children=[switch]),
        html.Div(children=[graph]),
    ])

    @app.callback(
        Output('graph', 'figure'),
        [Input('switch', 'value')],
    )
    def update_figure(value):
        print("Update value: ", value)

        if value == "A":
            # The main OSM tile server
            tiles = ["https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"]
        else:
            # Example of an alternative tile server
            tiles = ["http://a.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg"]

        print("Using tiles: ", tiles)

        mapbox_style = {
            "version": 8,
            "sources": {
                "osm": {
                    "type": 'raster',
                    "tiles": tiles,
                    "maxZoom": 23,
                    "tileSize": 256,
                }
            },
            "layers": [{
                "id": 'osm',
                "type": 'raster',
                "source": 'osm',
            }],
        }

        return dict(
            data=[
                go.Scattermapbox()
            ],
            layout=dict(
                title="Using tile server: {}".format(tiles[0]),
                mapbox=dict(style=mapbox_style)
            ),
        )

    return app


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

According to the logging output (and the title change) it is clear that the update from the radio button is working properly. However the map does not change accordingly. Only the initial setting is relevant (swapping the if condition simply shows the other tile server unconditionally).

It looks like the behavior is not specific to just the tile server settings -- other modifications also do not seem to update.

Expected behavior

I would have expected the map to change according to the changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions