RadioButtonGroup callback doesn't seem to work

Hi,

I was so hyped to see the update to callbacks in the recent update, and for the most part I grasped the concept. However, with the RadioGroup and RadioButtonGroup it doesn’t seem to work all the time.

I made a small example, that doens’t do what I’d expect it to:

from bokeh.plotting import show

from bokeh.io import output_notebook

from bokeh.layouts import column

from bokeh.models import CustomJS

from bokeh.models.widgets import Div, RadioButtonGroup, Button

output_notebook()

a = RadioButtonGroup(active = 0, labels=[‘one’,‘two’])

b = Div(text = ‘text’)

cb = CustomJS(args=dict(a=a,b=b),code = ‘’’

var val = a.get(‘active’)

var d = {

0:‘one’,

1:‘two’

}

var unitval = d[val]

b.set(‘text’,unitval);

b.trigger(‘change’);

‘’’)

c = Button(label=“Click here?”, button_type=“success”,callback=cb)

a.js_on_change(‘active’,cb)

show(column(a,b,c))

``

So, this code produces a radio button group with two buttons, and my hope was to trigger the callback by pressing the buttons, which should update the value of the Div text based on the button value (captured in ‘active’ field of the button group).

As a fallback option I also created a separate button with the same callback.

However, clicking either of the buttons doesn’t update the text field, and clicking the c button always updates the field to “one” regardless of the state of the radio group.

If I use RadioGroup instead, it seems to work in this example, but doesn’t work in a larger example I had, which is also super-strange…

Can anyone point me to extensive examples of callback usage with RadioButtons? Like, explaining what’s the difference between on_click, on_change, js_callbacks, js_on_click etc?

Hi,

This is working perfectly for me (i.e. the div updates on ever button press), so perhaps there is some platform specific problem? I guess at this point I would suggest a GH issue with more detailed information about system, browser, versions, etc.

BTW ".set" is no longer needed. A more up to date version of you callback looks like this:

  cb = CustomJS(args=dict(a=a,b=b),code = '''
    var val = a.get('active')
    var d = {
      0:'one',
      1:'two'
    }
    b.text = d[val];
  ''')

Tho it worked for me with your original code as well.

Thanks,

Bryan

···

On Jan 19, 2017, at 4:27 PM, TonyPlaysGuitar <[email protected]> wrote:

Hi,

I was so hyped to see the update to callbacks in the recent update, and for the most part I grasped the concept. However, with the RadioGroup and RadioButtonGroup it doesn't seem to work all the time.

I made a small example, that doens't do what I'd expect it to:
from bokeh.plotting import show
from bokeh.io import output_notebook
from bokeh.layouts import column
from bokeh.models import CustomJS
from bokeh.models.widgets import Div, RadioButtonGroup, Button

output_notebook()

a = RadioButtonGroup(active = 0, labels=['one','two'])
b = Div(text = 'text')
cb = CustomJS(args=dict(a=a,b=b),code = '''
        var val = a.get('active')
        var d = {
        0:'one',
        1:'two'
        }
        
        var unitval = d[val]
        
        b.set('text',unitval);
        b.trigger('change');
        ''')

c = Button(label="Click here?", button_type="success",callback=cb)
a.js_on_change('active',cb)

show(column(a,b,c))

So, this code produces a radio button group with two buttons, and my hope was to trigger the callback by pressing the buttons, which should update the value of the Div text based on the button value (captured in 'active' field of the button group).
As a fallback option I also created a separate button with the same callback.

However, clicking either of the buttons doesn't update the text field, and clicking the c button always updates the field to "one" regardless of the state of the radio group.

If I use RadioGroup instead, it seems to work in this example, but doesn't work in a larger example I had, which is also super-strange...

Can anyone point me to extensive examples of callback usage with RadioButtons? Like, explaining what's the difference between on_click, on_change, js_callbacks, js_on_click etc?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/00787b5a-f0c1-42e2-b9d2-79fb0d032b09%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

thanks for a fast answer!

I feel like I keep having pretty much the same issues - last time I submitted similarly weird and inconsistent behavior about checkbuttongroups here

Could you try the notebook I attached? The last plot more or less consistently has unresponsive buttons. I’ll see if I can reliably compile a similar example with the radiobuttons - if I can, I’ll open another issue on github.

Thanks again,

Anton

Bokeh_Button_Errors.ipynb (6.14 KB)