python 2.7 - cannot get response from Bokeh RadioButtonGroup -


i trying understand how use interactivity in radiobuttongroup using bokeh , customjs python function. have tweaked the example provided @ bokeh site plotting y=x^f. instead of using slider power f, toggle between 2 powers, f=0.5 , f=0.2. have followed manual , inserted radiobuttongroup in code using jupyter notebook. buttons showing , responsive, unable callback response out of toggling buttons.

any appreciated.

from math import pi    bokeh.io import output_file, show  bokeh.layouts import column  bokeh.models import columndatasource, customjs, slider, textinput, radiobuttongroup  bokeh.plotting import figure, output_notebook    output_notebook()    x = [x*0.005 x in range(0, 200)]  y = x    source = columndatasource(data=dict(x=x, y=y))    plot = figure(plot_width=400, plot_height=400)  plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)    def callback(source=source, input1=input1, window=none):      data = source.data      m= input1.active      if m==0:          f=.5      else:          f=2                x, y = data['x'], data['y']      in range(len(x)):          y[i] = window.math.pow(x[i], f)      source.trigger('change')    input1 = radiobuttongroup(labels=["power = .5", "power = 2."], active=0)    input1.button_type="success"  input1.js_on_change('active', customjs.from_py_func(callback))    layout = column(input1, plot)    show(layout)

i can not make bokeh.models.radiobuttongroup generate callback, bokeh.models.radiogroup can (i'm using bokeh version 0.12.4 maybe newer version facilitates radiobuttongroup generate callback). also, referencing input1 before declaring it. it's not needed input of callback function, inside can use cb_obj. see:

import bokeh import bokeh.plotting  bokeh.io.output_notebook()  x = [x*0.005 x in range(0, 200)] y = x  source = bokeh.models.columndatasource(data=dict(x=x, y=y))  plot = bokeh.plotting.figure(plot_width=400, plot_height=400) plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)  def callback(source=source, window=none):     data = source.data     m = cb_obj.active     if m==0:         f=.5     else:         f=2      x, y = data['x'], data['y']     in range(len(x)):         y[i] = window.math.pow(x[i], f)     source.trigger('change')  input1 = bokeh.models.radiogroup(labels=["power = .5", "power = 2."],active=0,                    callback=bokeh.models.customjs.from_py_func(callback))  layout = bokeh.layouts.column(input1, plot)  bokeh.io.show(layout) 

enter image description here


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -