I am trying to create an app with multiple sliders that affect the dataset that is plotted using hvplot
interactively. Here is a step by step reproducible example where using sample_data
from xarray
we create two range sliders that are used to define a mask for the dataset. The dataset is then plotted using hvplot
. I have tried @pn.depends
, pn.bind
, hvplot.bind
and obj.param.watch
to try and return an .interactive
xarray.Dataset` that is plotted. Realistically I will do this with 4 masks and 6 variables but I am not even sure how to get this working with the Panel building blocks.
import xarray as xr
import numpy as np
import panel as pn
import hvplot.xarray
pn.extension()
xd = xr.tutorial.open_dataset('eraint_uvz')
rsu = pn.widgets.RangeSlider(
name="U Slider",
start=xd.u.values.min(),
end=xd.u.values.max()
)
rsv = pn.widgets.RangeSlider(
name="V Slider",
start=xd.v.values.min(),
end=xd.v.values.max()
)
pn.Column( rsu , rsv )
xd['u_masked'] = xr.where((xd.u > rsu.value[0]) & (xd.u < rsu.value[1]) & (xd.v > rsv.value[0]) & (xd.v < rsv.value[1]), 1, np.nan)
out_plot = xd.u_masked.sel(level=200,month=1).hvplot()
pn.Column( out_plot )