Kaspacainoombro
Kaspacainoombro

Reputation: 161

Python Panel How to force the update of the widget.Select

I have this Panel widget defined:

import panel as pn
demo = pn.widgets.Select(name='Demo', options=datasource)

How can i force the widget to update, when the datasource is also updated? I tried with this:

demo.param.update()

inside the function that also changes the datasource but it does not work. Any suggestions? Thank you.

Upvotes: 0

Views: 1555

Answers (3)

ChuckLewis
ChuckLewis

Reputation: 26

I am able to do this by using param as a method in the callback and defining the widget later on. So, something like:

demo = param.Selector(objects=[])
@pn.depends('demo')
def _func(self):
    new_options = []
    for i in something:
        option = something*2
        new_options.append(option)
    self.param.demo.optons = new_options

....

widgets = {'demo': pn.widgets.Select}
layout = pn.template.VanillaTemplate(sidebar=pn.Column(pn.WidgetBox(pn.Param(widgets=widgets)))

Upvotes: 0

Kaspacainoombro
Kaspacainoombro

Reputation: 161

Just for others reference:

import panel as pn
demo = pn.widgets.Select(name='Demo', options=datasource)

...
# after changing the datasource do:
demo.options = datasource

Upvotes: 0

JasonWang711
JasonWang711

Reputation: 23

If the datasource is also a panel object, you can do this:

def update_options(event):
    demo.options = event.new

datasource.param.watch(update_options, 'value')

Upvotes: 1

Related Questions