0

I can't get the Holoviz Panel ChechBoxGroup Widget to work when it is embedded. I can select the options but the output is not updated. However, if using the RadioBoxGroup with my code it all works as intended. However I need that feature to select multiple things.

In a Jupyter Notebook I have the following code:

import panel as pn
pn.extension()

CheckBoxes = pn.widgets.CheckBoxGroup(value=['1'], options=['1','2','3','4'])

@pn.depends(CheckBoxes.param.value)
def callback(value):
    sum = 0
    for i in range(len(value)):
        sum = sum + int(value[i])
    return sum

row = pn.Row(CheckBoxes, callback)
row.embed()

Changing it up a bit to use the RadioBoxGroup

import panel as pn
pn.extension()

CheckBoxes = pn.widgets.RadioBoxGroup(value=['1'], options=['1','2','3','4'])

@pn.depends(CheckBoxes.param.value)
def callback(value):
    return value

row = pn.Row(CheckBoxes, callback)
row.embed()

And everything works as intended. Thanks in advance!

Marzee
  • 1

2 Answers2

0

In both cases, the embed method does not work properly. I suggest you use widgets only. For example,

import panel as pn
pn.extension()

CheckBoxes = pn.widgets.CheckBoxGroup(name='Checkbox Group',value=['1'], options=['1','2','3','4'])

text = pn.widgets.TextInput()

@pn.depends(CheckBoxes.param.value, watch=True)
def callback(value):
    sum = 0
    print ('working')
    for i in range(len(value)):
        sum += + int(value[i])
    text.value = str(sum)

row = pn.Row(CheckBoxes, text)

row

here you have a screenshot working

nghenzi
  • 26
  • 1
  • 4
0

Previous answer is not correct (I do not have enough reputation to comment). The code in previous answer works perfectly using Jupyter kernel or Bokeh Server. However, initial question was regarding embed() function not working correctly. And the answer does not solve this problem. Embed() function is still not working. The abovementioned problem with embed() occurs only with widgets for Multiple values. The problem is hidden in embed_state() function within embed.py (part of panel lib). The issue is caused by variable cross_product:

cross_product = list(product(*[vals[::-1] for _, _, vals, _ in values]))

Cross_product contains all combination of widgets values, in our case it is empty, therefore output is not updated. I suppose there is a bag in embed function for widgets with Multiple values (also, it does not working for param.ListSelector()). Meanwhile it works perfectly for single value objects:

import param
import panel as pn
pn.extension()
class a(param.Parameterized):

    coarse0 = pn.widgets.MultiSelect(name='coarse0', options=[0,1,2,3,4],size=8)
    decile = param.ObjectSelector(default=3, objects=[3,9])
    decile1 = param.ObjectSelector(default=100, objects=[100,1000])

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.coarse0.value = [0,1]

    @pn.depends("coarse0.value","decile","decile1")
    def callback_dec(self):
        return self.decile+self.coarse0.value[-1],self.coarse0.value,self.decile1
w = a()    
r = pn.Column(w.coarse0,w.param,w.callback_dec)    

The code above works as intended. But if you try to use embed function, coarse0 widget will be frozen with default value [0,1]. Other two single value widgets will be just fine (the output is updated).

r.embed(max_states =10000,max_opts=10000, progress=True)

So, the solution is not using embed function with widgets of Multiple values, use only single values widgets until the bag is fixed.