我想自动将散景DataTable的宽度调整为屏幕大小。但我找不到正确的方法。这行代码应该可以工作:
data_table = DataTable(source=source, columns=columns, height = 300, sizing_mode = 'scale_width', fit_columns=True)
但事实并非如此。我的数据表保持相同的宽度。 有谁知道如何解决这个问题?
谢谢。
答案 0 :(得分:0)
我担心使用DataTable
的当前实现是不可能的 - 如果您没有指定显式宽度(以像素为单位),则宽度将设置为600px
。
欢迎您在Bokeh的GitHub上创建功能请求。
答案 1 :(得分:0)
从2.2.3版开始(可能更早),您可以使用sizing_mode
:
import pandas as pd, numpy as np, random, string
from bokeh.models import ColumnDataSource, DataTable, TableColumn
from bokeh.plotting import show
df = pd.DataFrame(np.random.randint(0,100,size=(100, 12)), columns=[(random.randint(1,30) * random.choice(string.ascii_uppercase)) for col in range(12)])
data_table = DataTable(columns = [TableColumn(field=c, title=c) for c in df.columns], sizing_mode='stretch_width', source = ColumnDataSource(df))
show(data_table)