I’m trying to create a dynamic view of a geopandas dataframe
that contains several data columns and associated polygon geometries.
Out of the box with hvplot
, I can achieve this with:
my_geopandas_dataframe.hvplot.polygons(groupby="date")
But I’m trying to combine this view in a layout with some other hv elements, using a dynamic map and some panel widgets:
polys = gv.Polygons(my_geopandas_dataframe, vdims=["date"])
date_widget = pn.widgets.Select(name='Date', options=dates)
@pn.depends(date=date_widget
my_plot(date=date):
# How can I show polygons from only rows with the date value?
selected_polys = polys.select(...)
...other elements using date...
return gvts.CartoDark() * other elements * selected_polys
pn.Row(date_widget, hv.DynamicMap(my_plot))
1. How can I show polygons from only rows with the date value?
EDIT: One way I’ve done this is by creating a gv.Dataset
using the geopandas dataframe and then slicing that using my date
value:
dataset = gv.Dataset(my_geopandas_dataframe, kdims=['Longitude', 'Latitude'], vdims=['date'])
Then in the plotting function:
...
my_plot(date=date):
...
selected_polys = dataset.select(date=[date]).data.hvplot.polygons(geo=True)
...
But this seems like slicing the data directly and creating a new gv.Polygons
each time, not slicing the data inside of the gv.Polygons
element. This would be the same as just slicing the GeoPandas dataframe directly here and creating a new gv.Polygons
element:
gv.Polygons(my_geopandas_dataframe[...etc]
)
… wondering if there is a better way to do this?
Note: The geo=True
on the hvplot
is necessary for the kdims
to be ['Longitude', 'Latitude']
instead of the default ['x','y']
so that the plot plays nice with the WMTS
(gvts.CartoDark()
) elements in the layout.
2. I would also like to be able to select polygons with Bokeh’s tap
tool.
Do I also need to add a Selection1D
stream to the DynamicMap
, or is there a way to get the selected row directly from the DynamicMap’s Tap selection tool?