holoviz/param/panel: updating Str or HTML panes via python callback

572 views Asked by At

I would like to know if there is a way to update a panel pane content through a python callback.

If I define a Parameterized custom class the following way:

import panel as pn
pn.extension()
import param

class Myclass(param.Parameterized):
    letter = param.ObjectSelector(
        objects=['a', 'b', 'c', 'd'],
        default='b',        
    )
    
    @param.depends('letter')
    def text(self):
        return(pn.pane.Str(self.letter))
    
instance = Myclass()

If I output this instance in my notebook, I get the following:

pn.Row(instance.param.letter, instance.text)

yields:

instance representation

However, when I select another entry in the dropdown list, the text on the right is not updated:

Another view on instance

I know that the parameter has been updated, and that the text callback is fired (through debugging). Yet, no update is done in my notebook.

I feel that this example is very similar to the Sine wave example in the documentation (https://panel.holoviz.org/user_guide/Param.html), but I don't get what I am doing wrong...

Ideally, the answer should also work with a panel.pane.HTML as well as a panel.pane.Str.

1

There are 1 answers

1
Sander van den Oord On BEST ANSWER

I tried your code in jupyter notebook and it works: the text gets updated when the dropdown changes.

If I try it in my jupyter lab it doesn't work, but I have that more often. I think with me it's a jupyter version / installation thing.

So I think your code is correct. You could try updating your jupyter notebook or your panel or param packages.