如何在没有默认行填充颜色的情况下构建Bokeh数据表?

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

Bokeh中是否有一种方法可以在构建数据表时减少备用行的背景格式?

from datetime import date
from random import randint

from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
from bokeh.io import output_file, show

output_file("data_table.html")

data = dict(idx=[randint(0, 100) for i in range(10)],
            values=[randint(0, 100) for i in range(10)])
source = ColumnDataSource(data)

columns = [TableColumn(field="idx", title="Index"),
           TableColumn(field="values", title="Values")]
data_table = DataTable(source=source, columns=columns, width=400, height=280)

show(data_table)

[创建数据表时,其行以交替的白灰色填充显示,但是对于我要构建的特定数据表,我需要所有行都是白色/透明的,在Bokeh中可以实现吗?

我已经查看了Datatable documentation,但似乎没有专用于此的参数。有background参数,但是在尝试以下选项后不会影响生成的数据表:

from bokeh.colors.rgb import RGB

data_table = DataTable(source=source, columns=columns, width=400, height=280, background='red')
data_table = DataTable(source=source, columns=columns, width=400, height=280, background='#000000')
data_table = DataTable(source=source, columns=columns, width=400, height=280,
                       background=RGB(125, 54, 89))

足够有趣的是,当我提供无效参数(例如background='000000')时,Bokeh返回ValueError,其中说明可接受或不可接受的参数:

ValueError: expected an element of either Enum(...'red',...),
Regex('^#[0-9a-fA-F]{6}$'),
Regex('^rgba\\(((25[0-5]|2[0-4]\\d|1\\d{1,2}|\\d\\d?)\\s*,\\s*?){2}(25[0-5]|2[0-4]\\d|1\\d{1,2}|\\d\\d?)\\s*,\\s*([01]\\.?\\d*?)\\)'),
Regex('^rgb\\(((25[0-5]|2[0-4]\\d|1\\d{1,2}|\\d\\d?)\\s*,\\s*?){2}(25[0-5]|2[0-4]\\d|1\\d{1,2}|\\d\\d?)\\s*?\\)'),
Tuple(Byte(Int, 0, 255), Byte(Int, 0, 255), Byte(Int, 0, 255)),
Tuple(Byte(Int, 0, 255), Byte(Int, 0, 255), Byte(Int, 0, 255), Percent) or RGB, got '000000'

我在这里缺少数据表的启动器吗?

而且,我知道有一个option可以用HTMLTemplateFormatter格式化单元格,但是应该避免这种情况,因为我已经对某些列使用了format选项。

python bokeh
1个回答
1
投票

没有内置的方法可以做到这一点。但是您可以使用自定义文档模板,并向其中添加一些CSS规则。带有灰色背景的行应遵循以下CSS规则:

.bk-root .slick-row.odd {
    background: #fafafa;
}
© www.soinside.com 2019 - 2024. All rights reserved.