Panel breaks when using apply.opts

I am using panel and hvplot to make a plot where I can use a slider widget to set the xlims.

Here is the example code:

import xarray as xr
import hvplot.xarray  # noqa
import panel as pn
pn.extension()

air_ds = xr.tutorial.open_dataset('air_temperature').load()
air = air_ds.air

# setup an image element
image = air_ds.air.sel(time='2013-01-01T00:00:00', method='nearest').hvplot() 

# Setup a panel slider 
Xslide = pn.widgets.RangeSlider(start=float(air_ds.lon.min().data), 
                                end=float(air_ds.lon.max().data), 
                                step=0.1)

@pn.depends(Xslide)
def set_xlim(Xlims):
    # this function does what apply.opts is supposed to 
    return image.opts(xlim=Xlims).opts(width=500)

Now I can plot in two different ways using the following in two cells of a notebook:
Cell1: pn.Row(Xslide, set_xlim), and Cell2: image.apply.opts(xlim=Xslide)

then I get the following. Everything works fine, if I move the time slider then both the images change their xlims in correspondence.

If I alternatively try to put everything in the same panel
pn.Column(Xslide, set_xlim, image.apply.opts(xlim=Xslide)), then the image generated using the apply.opts does not respond to the slider. To be precise it responds only once, the first time the slider is moved it will move but then after that the connection breaks. The other notable thing is that the image generated previously using apply.opts still keeps responding.

.

Can’t reproduce any issues here, this works as expected for me:

import xarray as xr
import hvplot.xarray  # noqa
import panel as pn
pn.extension()

air_ds = xr.tutorial.open_dataset('air_temperature').load()
air = air_ds.air

# setup an image element
image = air_ds.air.sel(time='2013-01-01T00:00:00', method='nearest').hvplot() 

# Setup a panel slider 
Xslide = pn.widgets.RangeSlider(start=float(air_ds.lon.min().data), 
                                end=float(air_ds.lon.max().data), 
                                step=0.1)

pn.Column(Xslide, image.apply.opts(xlim=Xslide))
1 Like