You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importdashimportpandasaspdimportplotly.graph_objectsasgofromdashimportdcc, htmlfromdash.dependenciesimportInput, Outputapp=dash.Dash(__name__)
data= {"Latitude": [37.7749], "Longitude": [-122.4194], "Location": ["San Francisco"]}
df=pd.DataFrame(data)
# Create a map using go.Scattermapboxfig=go.Figure(
go.Scattermapbox(
lat=df["Latitude"],
lon=df["Longitude"],
mode="markers",
)
)
# Add tile layers to the mapfig.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")])defdisplay_modal(clickData):
ifclickDataisnotNone:
returnTruereturnFalseif__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.
The text was updated successfully, but these errors were encountered:
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
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
Describe your context
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: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 deprecatedStamen
tile layer. The lack of any errors made it difficult to track down the root cause of the problem.The text was updated successfully, but these errors were encountered: