I have a Select
that chooses the data variable from an xarray dataset and I have written this little loop to identify and create the widgets necessary to select the data needed for a QuadMesh
:
widget_box = pn.WidgetBox('# WidgetBox')
sel_dict = {}
for (i,d) in enumerate(xds[var_name].dims):
for (j,c) in enumerate(xds[var_name].coords):
if d == c and (d != 'lon' and d != 'lat'):
if xds[var_name].coords[c].dtype == np.dtype('<M8[ns]'):
time_list = []
for i, el in np.ndenumerate(xds.P0.coords['time'].values):
time_list.append(np.datetime_as_string(el, timezone='UTC'))
time_slider = pnw.DiscreteSlider(options=time_list)
sel_dict[d] = time_slider
widget_box.append(time_slider)
else:
sel_dict[d] = pnw.DiscreteSlider(options=xds[var_name].coords[c].values.tolist())
widget_box.append(sel_dict[d])
At the moment if I simply add .value
to the Sliders I get a dict that correctly selects when passed to sel
but has static values. I would like to retain the interactivity of code like xds.ES.interactive.sel(time=pnw.DiscreteSlider,pres1=pnw.DiscreteSlider).hvplot()
which renders the interactive widgets and the plot (which is linked to the widgets). I tried passing a dict of the widgets themselves and other variations but I can not seem to get it. The workflow should be :
- Use a
Select
to choose data variable to plot - Use the value of the
Select
in my little loop to create the widgets necessary. - Render the widgets and the plot bith linked and interactive.
I am not sure if I am using the right APIs within Panel
, so please let me know if there is a more Panel
way of doing what I need to do.
Oh and here is what my xarray.Dataset
looks like. As you can see different variables have different dimensions hence the need to dynamically creating their widgets.