Pass polygon values to external DataFrame

Hi. I’m hoping this is a relatively straightforward query, and I’ve just misunderstood how to link two items.
I have a GeoPandas DataFrame from which I am plotting polygons in Geoviews. I have a separate Pandas DataFrame that contains some data that I want to plot. I don’t want to join the DataFrames but I would like that when a user clicks a polygon, all the information in the GeoPandas Dataframe row behind that polygon is passed to a variable that can be used to slice the Pandas DataFrame. Using some of the help in this forum I have the following code, and I know that sel.index holds the polygon index.
I just don’t understand how to set up the interactivity. Any guidance would be really appreciated.
Thanks

import geopandas as gpd
import geoviews as gv
import holoviews as hv
gv.extension('bokeh')
hv.extension('bokeh')

df = gpd.read_file('https://raw.githubusercontent.com/ajggeoger/JNCCLocalIndex/main/data/DarkPeak/datasubset.geojson')
to_keep = ['polygon_id', 'ID', 'main_habit', 'Confidence', 'Area_Ha', 'geometry'] 
mydf = df[to_keep]
mydf = mydf.to_crs("EPSG:4326")

polys = gv.Polygons(mydf, vdims=['main_habit'])

sel = hv.streams.Selection1D(source=polys)#, index=[0])

polys.opts(
tools=['hover', 'tap'], width=600,
)


pn.Row(polys, mydf.iloc[sel.index]) 
# but what I really want is the information from mydf to be updated every time a polygon is clicked
# and for it to be saved as a variable that I can use to slice a different dataframe

HoloViews streams (just like all of Panel) are built on top of param. Parameters allow you depend them either using explicit callbacks (stream.param.watch(callback, 'index')) or by using the pn.depends decorator or pn.bind function. In this example we will bind the current index to the argument of the get_selection function so that every time the index changes it will an update:

sel = hv.streams.Selection1D(source=polys, index=[0])

def get_selection(index):
   return mydf.iloc[index]

pn.Row(polys, pn.bind(get_selection, index=sel.param.index)) 

Thanks for this. I will update my Panel install and try it out :slight_smile: