Thanks, @ahuang11! If you want to see how it looks using pn.bind
from panel 0.10.1 instead of @depends
, it’s just:
import panel as pn
import numpy as np
import xarray as xr
import holoviews as hv
import hvplot.xarray
pn.extension()
ds = xr.tutorial.open_dataset('air_temperature')
image = ds.hvplot('lon', 'lat')
stream = hv.streams.Tap(source=image, x=-88 + 360, y=40)
def timeseries(x, y):
return ds.sel(lon=x, lat=y, method='nearest').hvplot('time')
pn.Column(image, pn.bind(timeseries, x=stream.param.x, y=stream.param.y))
I.e., basically the same, but now you can write your callback function as just a regular Python function now, with no decorator, and then later bind its arguments to widgets or to stream parameters when you want to put it in a panel.
[UPDATED with working code; I needed to add .dmap()]
You can also write this even more simply using the new .interactive
support in hvPlot, which lets you eliminate the callback entirely:
import panel as pn
import numpy as np
import xarray as xr
import holoviews as hv
import hvplot.xarray
pn.extension()
ds = xr.tutorial.open_dataset('air_temperature')
image = ds.hvplot('lon', 'lat')
stream = hv.streams.Tap(source=image, x=-88+360, y=40)
timeseries = ds.interactive.sel(lon=stream.param.x, lat=stream.param.y,
method="nearest").hvplot('time')
pn.Column(image, timeseries.dmap())