无法使数据表响应-Bokeh
unable to make Datatable responsive -Bokeh
我试图通过将 sizing_mode 属性设置为 "stretch_both" 来使散景数据表响应。但与其他模型不同,它不适用于数据表的 datatable.width,显示为固定的
data_table = DataTable(
source=sourceDT,
columns=columns,
height=200,
fit_columns=True,
editable=False,
index_position=None,name="DT"
)
data_table.sizing_mode = "scale_width"
我怎样才能使这个响应式。有人请
遗憾的是 sizing_mode
对 DataTable
没有影响。解决方法是动态设置 table 宽度的滑块 (Bokeh v1.0.4)。
from bokeh.io import show
from bokeh.layouts import widgetbox
from bokeh.models import ColumnDataSource, Slider, DataTable, TableColumn, CustomJS
source = ColumnDataSource(dict(x = list(range(6)), y = [x ** 2 for x in range(6)]))
columns = [TableColumn(field = "x", title = "x"), TableColumn(field = "y", title = "x**2")]
table = DataTable(source = source, columns = columns, width = 320)
slider = Slider(start = 1, end = 100, value = 6, step = 1, title = "i", width = 300)
callback_code = """ i = slider.value;
new_data = {"x": [1, 2, 3, 4, 5], "y": [1, 4, 9, 16, 25]}
table.source.data = new_data
table.width = 320 + i * 25; """
callback = CustomJS(args = dict(slider = slider, table = table), code = callback_code)
slider.js_on_change('value', callback)
show(widgetbox(slider, table))
我试图通过将 sizing_mode 属性设置为 "stretch_both" 来使散景数据表响应。但与其他模型不同,它不适用于数据表的 datatable.width,显示为固定的
data_table = DataTable(
source=sourceDT,
columns=columns,
height=200,
fit_columns=True,
editable=False,
index_position=None,name="DT"
)
data_table.sizing_mode = "scale_width"
我怎样才能使这个响应式。有人请
遗憾的是 sizing_mode
对 DataTable
没有影响。解决方法是动态设置 table 宽度的滑块 (Bokeh v1.0.4)。
from bokeh.io import show
from bokeh.layouts import widgetbox
from bokeh.models import ColumnDataSource, Slider, DataTable, TableColumn, CustomJS
source = ColumnDataSource(dict(x = list(range(6)), y = [x ** 2 for x in range(6)]))
columns = [TableColumn(field = "x", title = "x"), TableColumn(field = "y", title = "x**2")]
table = DataTable(source = source, columns = columns, width = 320)
slider = Slider(start = 1, end = 100, value = 6, step = 1, title = "i", width = 300)
callback_code = """ i = slider.value;
new_data = {"x": [1, 2, 3, 4, 5], "y": [1, 4, 9, 16, 25]}
table.source.data = new_data
table.width = 320 + i * 25; """
callback = CustomJS(args = dict(slider = slider, table = table), code = callback_code)
slider.js_on_change('value', callback)
show(widgetbox(slider, table))