私は、BokehとCustomJSをPython関数で使用して、RadioButtonGroupでインタラクティブ機能を使用する方法を理解しようとしています。私はy = x^fをプロットするためにthe example provided at the Bokeh siteを調整しました。パワーfにスライダを使用する代わりに、f = 0.5とf = 0.2という2つのパワーを切り替えたいと思います。私はこのマニュアルを読んで、Jupyterノートブックを使って自分のコードにRadioButtonGroupを挿入しました。ボタンは表示され、応答しますが、ボタンを切り替えることでコールバック応答を得ることができません。はBokeh RadioButtonGroupからの応答を得ることができません
ご協力いただければ幸いです。
from math import pi
from bokeh.io import output_file, show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomJS, Slider, TextInput, RadioButtonGroup
from bokeh.plotting import Figure, output_notebook
output_notebook()
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, input1=input1, window=None):
data = source.data
m= input1.active
if m==0:
f=.5
else:
f=2
x, y = data['x'], data['y']
for i 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)
はそれを指摘するためにありがとうございました。ところで、input1宣言の位置を変えて、RadioButtonGroupをBokeh 0.12.5で正常に動作させました。 –
ありがとうございます。 0.12.5に更新する時間。 –