How to change opts parameters via parameters of panel

Hello, I would like change the color_levels value with panel of already plotted figure, I am trying to do it in that way:

import param
import panel as pn
import numpy as np
import holoviews as hv
from holoviews.streams import Pipe

class Layout(param.Parameterized):
    level      = param.Number(0.3, bounds=(0.0, 1))
    
    def __init__(self, **params):
        super(Layout, self).__init__(**params)
        self._waterlvl         = [0,self.level,1] 
        
    @param.depends("level", watch=True)
    def _change_levels(self,):
        self._waterlvl = [0,self.level,1] 
        
layout = Layout()

pipe = Pipe(data=[])
pipe.send(np.random.rand(10,10))
Image = hv.DynamicMap(hv.Image, streams=[pipe]).apply.opts(color_levels=layout._waterlvl) 
pdmap = pn.panel(Image)
playout = pn.panel(layout)
pn.Row(playout, pdmap)

I guess it just doesn’t update when parameter changes. I also tried to get the object through render and call update(0) method, but I faild with that as well. Could you help me, please?

your _waterlevel attribute must be a parameter:

import param
import panel as pn
import numpy as np
import holoviews as hv
from holoviews.streams import Pipe
pn.extension()

class Layout(param.Parameterized):
    level = param.Number(0.3, bounds=(0.0, 1))
    _waterlvl = param.List(precedence=-1)
    def __init__(self, **params):
        super().__init__(**params)
        self._waterlvl         = [0,self.level,1] 
        
    @param.depends("level", watch=True)
    def _change_levels(self,):
        self._waterlvl = [0,self.level,1] 
        
layout = Layout()

pipe = Pipe(data=[])
pipe.send(np.random.rand(10,10))
Image = hv.DynamicMap(hv.Image, streams=[pipe]).apply.opts(color_levels=layout.param._waterlvl) 
pdmap = pn.panel(Image)
playout = pn.panel(layout)
pn.Row(playout, pdmap)
1 Like

Thank you very much @xavArtley!!!

1 Like