Streaming Map Coordinates in Hover Data When Interacting with Plotly Map

Hello,

Does anyone know if it is possible to access (latitude, longitude) coordinates that correspond to the current location of the mouse pointer as it hovers over a Plotly map embedded in a Panel application?

Chris

1 Like

I believe it will be available in the hover_data parameter of the Plotly pane. See Plotly — Panel v0.14.2 (holoviz.org).

I have an example with hover_data here Plotly (awesome-panel.org).

1 Like

Thanks @Marc - I just went down that path to no avail unfortunately. Here’s the example I put together.

from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=df.fips, z=df.unemp,
                                    colorscale="Viridis", zmin=0, zmax=12,
                                    marker_opacity=1, marker_line_width=0))
fig.update_layout(mapbox_style="mapbox://styles/mapbox/light-v10", mapbox_accesstoken=MAPBOX_ACCESS_TOKEN,
                  mapbox_zoom=3.25, mapbox_center = {"lat": 38, "lon": -97})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})

p = pn.pane.Plotly(fig)
pn.Row(p.controls(), p)

Here’s what I’m seeing in hover data: {“points”: [{“curveNumber”: 0, “pointNumber”: 240, “pointIndex”: 240, “location”: “06109”, “z”: 6.2}]}

Not quite sure what to make of this data.