Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
colinbrust opened this issue Nov 30, 2023 · 0 comments
Labels
bug something broken P3 not needed for current cycle sev-2 serious problem

Comments

@colinbrust
Copy link

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.

@Coding-with-Adam Coding-with-Adam added bug something broken sev-2 serious problem P3 not needed for current cycle labels Dec 1, 2023
@Coding-with-Adam Coding-with-Adam removed the P3 not needed for current cycle label Jan 18, 2024
@gvwilson gvwilson self-assigned this Jul 25, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added the P3 not needed for current cycle label Aug 13, 2024
@gvwilson gvwilson changed the title [BUG] clickData from go.ScatterMapbox does not work when an invalid tile layer is specified. clickData from go.ScatterMapbox does not work when an invalid tile layer is specified. Aug 13, 2024
@gvwilson gvwilson changed the title clickData from go.ScatterMapbox does not work when an invalid tile layer is specified. clickData from go.ScatterMapbox does not work when an invalid tile layer is specified Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 not needed for current cycle sev-2 serious problem
Projects
None yet
Development

No branches or pull requests

3 participants