通过taptool回调呈现数据表

问题描述 投票:0回答:1

从我在散景文档的有限评论中可以看出,能够点击绘图上的字形然后呈现对话框或数据表是一个尚未提供的功能。我不希望在选择字形之前显示数据表。理想情况下也喜欢隐藏Dialog或Datatable的能力。

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

datatable modal-dialog bokeh
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.