Extracting name of point-based station based on a click on a geoviews map?

Hi there,

Thanks a ton for developing/supporting the Holoviews/Panel ecosystem.

I am currently using the Panels interact method to explore a large meteorological dataset, consisting of records across many weather stations located across Canada. Currently, along with several other reactive data exploration options, the user can choose which weather station to analyze via the Dropdown widget, which is automatically configured given the list of station names to interact. Choosing a different station name from this list drives a reactive update of the data visualization. However, since the station names are confusing and there are also 700+ stations within the database, the dropdown menu is limiting in practice to explore the data! Instead, in lieu of a dropdown list I need to develop a routine that allows a user to view a map of Canada that includes points of all station locations, and click on a point representing the station they are interested in. This click would drive the equivalent operation as the Dropdown menu, in terms of reactive plotting. What is the best avenue to do this? I am nearly certain this is possible in principle but am struggling to pull this together in practice. Here is the current minimal basic code that develops a geoviews object with a few of these stations. Moving from this object, to use of this object to extract and use the station names to drive subsequent data analysis, is where I’d like to go. Thoughts/questions welcome!

Jeremy

import pandas as pd
import geoviews as gv
from geoviews import opts

station_locations=pd.DataFrame(data={'x':[-93.86,-92.67,-94.06],
                                     'y':[51.02,51.11,52.64],
                                     'station':['s1','s2','s3']})
points=gv.Points(station_locations,vdims="station").opts(opts.Points(global_extent=True, width=500, height=475, size=5, color='black'))
tile=gv.tile_sources.OSM
pn.Row(tile * points)

Welcome to HoloViz! This is definitely something well suited to HoloViz tools, but I agree that interact is probably not going to give a very good user experience in this case. Instead, I’d use HoloViews Streams as described at Custom Interactivity — HoloViews v1.14.8 , where it’s easy to set up callbacks that are invoked when events like clicks occur on a plot. I can’t think of a specific existing example covering what you need, i.e. finding the nearest point to the click, but that’s definitely doable. You may find a good example somewhere in the HoloViews docs or examples.pyviz.org examples, if you look around, or maybe someone else here can paste something they’ve done.