How to change/update the bounds of a param.Range object

Hello

I am building a small dashboard app using Panels and Params. For one of its plots I need to update the bounds (limits of the UI’s slider) of a param.range object accordingly to another param object value. I already can change the range values accordingly to this other param object however I cannot change the bounds of this range object.

As a example I have a kind object and a slider object:

class C(param.parametrized):
   kind = param.Selector(default="temperature", objects=["temperature", "pression","elevation"]
  slider_param = param.Range(default(0,1), bounds=(0,1))
@param.depends("kind",watch=True)
def update_slider(self):
    minmax = self._getMinAndMax(kind)
    slider_param = minmax
    # Is there a way to change the bounds range of this slider_param object ?
    # to make the slider pretty

thanks

Hello I have found a way to do. But I am not sure if it is recommended or a good way to do that:

obj = C()
obj.params()["slider_param"].bounds = new_bounds
1 Like

It is one way to do it @dashAllTheThings :+1:

Alternatively you can use obj.param.slider_param.bounds = new_bounds. I’ve seen that used more.

Update: changed .params to param.

It’s actually without the s:

obj.param.slider_param.bounds = new_bounds

that is equivalent to:

obj.param['slider_param'].bounds = new_bounds
1 Like

Hi all, is there a way to add a watcher on the bounds attribute of a parameter (or any other attribute for that matter)?

In fact yes, it’s vaguely described in Dependencies and Watchers — param v2.1.0, and maybe in other places too.

There are 2 APIs:

  • param.watch(<callback>, <parameter_name>, what=<parameter_attribute>)
  • @param.depends(<parameter_name>:<parameter_attribute>, watch=True)
from param import Parameter, Parameterized, depends

class P(Parameterized):
    a = Parameter(0, label='init a')
    b = Parameter(0, label='init b')

    @depends('a:label', watch=True)
    def on_a_label(self):
        print('Updating a.label', self.param['a'].label)

p = P()

p.param['a'].label = 'new a'

def on_b_label(event):
    print('Updating b.label from', event.old, 'to', event.new)

p.param.watch(on_b_label, 'b', 'label')

p.param['b'].label = 'new b'

1 Like