散景按钮在交互式情节中不起作用

Bokeh Button is not working in the interactive plot

所以我只是想为我的散景交互图实现一个按钮,但无论我做什么,每次按下按钮时,图中都没有任何反应。我已经尝试了几乎所有我看到的例子,但没有任何效果,按钮也没有任何功能。我很困惑为什么。有什么建议吗?

from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import Figure, output_file, show
from bokeh.models.widgets import Button

x = [x*0.05 for x in range(0, 200)]
y = x
button = Button()
source = ColumnDataSource(data=dict(x=x, y=y))

plot = Figure(plot_width=400, plot_height=400)

button.js_on_click(CustomJS(args=dict(source=source), code="""
   var data = source.data;
   x = data['x']
   y = data['y']

   for (i = 0; i < x.length; i++) {
      y[i] = Math.pow(x[i], 6)
   }
   
   source.change.emit();
"""))
        
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
layout = column(button, plot)
show(layout)

#curdoc().add_root(row(button, plot))

现代 JS 要求您正确声明变量。将 var 放在 xyi 的定义前面。