plotly / plotly/dash

`clickData` from `go.ScatterMapbox` does not work when an invalid tile layer is specified

Open
#2,705 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3 sev-2
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Describe your context

dash                      2.13.0
dash-bootstrap-components 1.5.0
dash-core-components      2.0.0
dash-daq                  0.5.0
dash-html-components      2.0.0
dash-loading-spinners     1.0.0
dash-mantine-components   0.12.1
dash-table                5.0.0

Describe the bug

When using go.ScatterMapbox, clickData is not triggered if an invalid tile layer is specified. In the example below, the dialog box doesn't pop up when clicking the point on the map. Commenting out the invalid tile layer solves the problem:

import dash
import pandas as pd
import plotly.graph_objects as go
from dash import dcc, html
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

data = {"Latitude": [37.7749], "Longitude": [-122.4194], "Location": ["San Francisco"]}
df = pd.DataFrame(data)

# Create a map using go.Scattermapbox
fig = go.Figure(
    go.Scattermapbox(
        lat=df["Latitude"],
        lon=df["Longitude"],
        mode="markers",
    )
)

# Add tile layers to the map
fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        # A valid tile layer.
        {
            "below": "traces",
            "sourcetype": "raster",
            "sourceattribution": "USGS Map Tiles",
            "source": [
                "https://basemap.nationalmap.gov/arcgis/rest/services/USGSShadedReliefOnly/MapServer/tile/{z}/{y}/{x}"
            ],
        },
        # Here is an invalid tile layer.
        # If you comment out the dict below, the popup works as expected.
        {
            "below": "traces",
            "sourcetype": "raster",
            "source": [
                "https://asdf/{z}/{x}/{y}.png"
            ],
        },
    ],
    mapbox={"center": {"lon": -122.4194, "lat": 37.7749}, "zoom": 5},
)
app.layout = html.Div(
    [
        dcc.Graph(id="map", figure=fig),
        dcc.ConfirmDialog(
            id="modal",
            message="You clicked the point!",
        ),
    ]
)

# Display modal
@app.callback(Output("modal", "displayed"), [Input("map", "clickData")])
def display_modal(clickData):
    if clickData is not None:
        return True
    return False


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

Expected behavior

clickData should work even if an invalid tile layer is used. At the very least, it would be nice if an exception was thrown when an invalid tile layer is used (although that may be more of a Plotly issue). I discovered this issue because we were using a deprecated Stamen tile layer. The lack of any errors made it difficult to track down the root cause of the problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example using go.Scattermapbox, mapbox_layers, and dcc.Graph with one invalid raster tile source, then trace how map rendering affects the map clickData entry point. Done means the point click still triggers clickData despite the invalid layer, or the invalid layer produces a visible exception instead of silently preventing the event.

Written by the indexing model from the issue text.

Assessment

Tech stack
plotly, python
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.