我正在尝试在Bokeh中使用切换按钮,创建一个交互式网站,用户可以点击切换按钮选择要绘制哪些图形。
这些按钮将从一个文本文件中加载数据(包含两列x和y数据)。数据文件有两列,包含用空格分隔的x和y数据。
当切换按钮被选中时,相应的数据将被绘制;当取消选中时,该图形将被移除。
我目前遇到了传递参数到回调事件的问题,是否可能实现?
这些按钮将从一个文本文件中加载数据(包含两列x和y数据)。数据文件有两列,包含用空格分隔的x和y数据。
当切换按钮被选中时,相应的数据将被绘制;当取消选中时,该图形将被移除。
我目前遇到了传递参数到回调事件的问题,是否可能实现?
from bokeh.io import vform
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.models.widgets import Toggle
from bokeh.plotting import figure, output_file, show
output_file("load_data_buttons.html")
x = [0]
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)
callback = CustomJS(args=filename,dict(source=source), code="""
var data = source.get('data');
console.log(filename)
x = data['x']
y = data['y']
#load data stored in the file name and assign to x and y
source.trigger('change');
""")
toggle1 = Toggle(label="Load data file 1", type="success",callback=callback("data_file_1.txt"))
toggle2 = Toggle(label="Load data file 2", type="success",callback=callback("data_file_2.txt"))
layout = vform(toggle1, toggle2, plot)
show(layout)