Linking widget to holoviews element's parameters

I am trying to link a RangeSlider to the xlim of an image element. Since xlim is a parameter, it seems to me like using .link should allow me to link the slider’s value to element’s xlim (based on the docs here: https://panel.holoviz.org/user_guide/Links.html). However, my attempt does not seem to work.

It seems like the parameters of the elements are no exposed? Is there another way to do this?

This an attempt to solve the question : Two way link between a widget and a linked stream.

Here is the code:

import xarray as xr
import hvplot.xarray  # noqa
import panel as pn
from holoviews import streams
import holoviews as hv
pn.extension()

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

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

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

Xslide.link(image, value='xlim')

pn.Column(Xslide, image) #this generates a slider and image, but they are not linked. 

P.S. : I think I do understand how link works, because I could make this simple set of connected widgets:

slide1 = pn.widgets.RangeSlider(start=0, 
                                end=1,
                                step=0.1)

slide2 = pn.widgets.RangeSlider(start=0, 
                                end=1,
                                step=0.1)

slide1.link(slide2, value='value', bidirectional=True)

pn.Column(slide1, slide2)

Now just want to do the same, but connect to the xlim of a plot instead of second slider widget.

import xarray as xr
import hvplot.xarray  # noqa
import panel as pn
from holoviews import streams
import holoviews as hv
pn.extension()

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



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

# setup an image
image = air_ds.air.sel(time='2013-01-01T00:00:00', method='nearest').hvplot().apply.opts(xlim=Xslide.param.value_throttled)

# to have the slider in coherence with the zoom
# rangex = streams.RangeX(source=image)
# rangex.param.watch(lambda evt: setattr(Xslide, "value", evt.new), parameter_names=['x_range'], onlychanged=True)

pn.Column(Xslide, image)
2 Likes

This works like a charm. Thank you. :slight_smile:

Now I just need to figure out how to use streams along with parameters in classes. Is there some example that does that?