我正在bokeh服务器上运行一个应用程序(请参阅下面的测试代码)。我有一个可编辑的数据表(x和y列),一个用于选择表中行数的小部件,以及一个随数据源更新的y vs x图。
我可以很好地编辑slickgrid数据表中的一个单元格,它会突出显示图中更新的x-y坐标。但是,我无法弄清楚如何在编辑单元之后使单元格失去焦点,以使图覆盖整个数据源(所有行和列)。我可以手动选择所有单元格以获取显示所有数据点的图。或者,我可以单击散景图旁边的刷新按钮。但是我在问是否有一种简单的方法可以使单个编辑单元格散焦。
如果在编辑后我无法从单元格中取消聚焦(或取消选择),我想使用一个单独的切换按钮,该按钮允许数据源更新自身,并覆盖整个数据集。换句话说,我希望该按钮具有与散景图旁边的刷新按钮相同的功能。我该怎么办?
非常感谢。
'''
Use the ``bokeh serve`` command to run the example by executing:
bokeh serve test.py
at your command prompt. Then navigate to the URL
http://localhost:5006/test
in your browser.
'''
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import layout, widgetbox, column, row
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Slider, Select, Toggle, DataTable, TableColumn
from bokeh.plotting import figure
def Steps(attrname, old, new):
n = int(Pts.value)
x=[]
y=[]
for i in range(n+1):
x.append(i)
y.append(i)
source.data = dict(x=x,y=y)
x=[]
y=[]
source = ColumnDataSource(data=dict(x=x, y=y))
# Set up plot
plot0 = figure(plot_width=350, plot_height=350, title = "plot", x_axis_label = "x", y_axis_label = "y", toolbar_location = "right", match_aspect=True, aspect_scale=1.)
plot0.min_border = 40
plot0.line('x', 'y', source=source, line_width=3, line_alpha=1, color='#b3c100')
plot0.square('x', 'y', source=source, size=8, color="red", alpha=0.5)
plot0.yaxis.axis_label_text_font_size = "12pt"
plot0.yaxis.axis_label_text_font_style = "normal"
plot0.xaxis.axis_label_text_font_size = "12pt"
plot0.title.text_font_size = "16px"
plot0.xaxis.axis_label_text_font_style = "normal"
plot0.x_range.start = 0
plot0.y_range.start = 0
columns = [
TableColumn(field="x", title="x"),
TableColumn(field="y", title="y"),
]
data_table = DataTable(source=source, columns=columns, width=250, height=400, fit_columns=True, editable=True)
Pts = Select(title="No. of steps:", value='1', options=[format(x,'d') for x in range(1,11)])
#----------------------------------------------
for w in [Pts]:
w.on_change('value', Steps)
doc_layout = layout(children=[
[column(widgetbox(Pts, data_table)), plot0]
],
sizing_mode='fixed')
curdoc().add_root(doc_layout)
curdoc().title = "test"