通过taptool回调提供数据表

时间:2019-03-15 20:09:36

标签: datatable modal-dialog bokeh

从我对bokeh文档的有限回顾中可以看出,单击图上的字形然后显示对话框或数据表的功能尚不可用。在选择字形之前,我不希望显示数据表。理想情况下,还希望能够隐藏Dialog或Datatable。

似乎在0.10.0之后的某个时间不推荐使用bokeh.models.widgets.dialog。我可以使用它,但目前在python 3.7中不可用。有建议吗?

1 个答案:

答案 0 :(得分:0)

某些功能未得到正式支持,但有时可以提出类似的解决方法(已在Bokeh v1.0.4上测试):

from bokeh.plotting import figure, show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider, DataTable, TableColumn, CustomJS

plot = figure(tools = 'tap')
source = ColumnDataSource(dict(x = list(range(6)), y = [x ** 2 for x in range(6)]))
circles = plot.circle('x', 'y', source = source, size = 20)
slider = Slider(start = -1, end = 5, value = 6, step = 1, title = "i", width = 300)
columns = [TableColumn(field = "x", title = "x"), TableColumn(field = "y", title = "x**2")]
table = DataTable(source = source, columns = columns, width = 320)
plot.js_on_event('tap', CustomJS(args = {'table': table, 'source': source, 'slider': slider}, code = '''
        const selected_index = source.selected.indices[0] 
        if (selected_index != null) 
            table.height = 0;
        else
            table.height = slider.value * 25 + 25;'''))
callback_code = """ i = slider.value;
                    new_data = {"x": [0,1,2,3,4,5], "y": [0,1,4,9,16,25]}
                    table.source.data = new_data
                    table.height = i * 25 + 25;  """
callback = CustomJS(args = dict(slider = slider, table = table), code = callback_code)
slider.js_on_change('value', callback)
show(column(slider, plot, table))

结果: enter image description here