Access to the widget, linked to Parameter, in a Pane

Trying to notify users when a “parameter” is externally updated visually by changing the widgets background.

Not a problem if the widget is directly created, but couldn’t find a way for parameterized classes, example below.

I did try widget = pn.Param(pc).widget('param_string') which gives you a widget linked to the parameter value , but it’s a different widget, not the one in the displayed pane.

Is there a recommended way ?

Kind regards,
Oz

import param
import panel as pn
pn.extension()

class DemoParameterizedClass(param.Parameterized):
    param_string = param.String(default="str", doc="A string")
    
    def __init__(self, *param, **params): 
    
        super().__init__(*param, **params)

        self.text_widget = pn.widgets.TextInput(name='Text Input', placeholder='Enter a string here...')

pc = DemoParameterizedClass()
pane = pn.Column(pc.param, pc.text_widget)

pc.text_widget.background = 'green'

###
# How to DYNAMICALLY change the background of the widget representing param_string parameter  ??
##

pane

maybe pane[0].background = 'green' ??

The column and the row objects are only lists, then you can access with indexing

image

1 Like

Thanks for that, and yes that works for this example snippet, but hoping there is a way for programatically find the right widget(s), so more complicated layouts can be handled.

I have a feeling I am trying to solve it the wrong way around, maybe should be iterating through the parameters watchers, and update the linked widgets ?