I’m trying to use my own function inside the CustomJS.from_py_func(callback), but it does not seem to be working.
Based on the example at:
Here is a minimal example of what I am trying to do.
---------start of example---------------
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show
create my pow function
def Mypow(base,power):
return base**power
do a sanity check
print(‘Mypow test 2**4 is:’,Mypow(2,4))
output_file(“callback.html”)
x = [x*0.005 for 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, window=None):
data = source.get('data')
f = cb_obj.get('value')
x, y = data['x'], data['y']
for i in range(len(x)):
y[i] = window.Math.pow(x[i], f)
y[i] = window.Mypow(x[i], f) # attempt to use my pow function instead of Math.pow
source.trigger('change')
slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”,
callback=CustomJS.from_py_func(callback))
layout = column(slider, plot)
show(layout)
---------end of example---------------
This code produces the plot, but changing the slider has no effect on the plot.
Any help would be greatly appreciated! I’m happy to provide any additional information.
I am using python 3.5 with Bokeh 0.12.0, jupyter 1.0.0, flexx 0.4.1 on OSX 10.11.5
Thanks,
Andrew