简体   繁体   中英

Vertical alignment of text within Bokeh DataTable

I have the following code that produces a datatable in Bokeh:

from bokeh.models import DataTable, TableColumn, HTMLTemplateFormatter

data = {'A': ['A1', 'A2', 'A3', 'A4'],
        'B': ['B1', 'B2', 'B3', 'B4'],
        'C': ['C1', 'C2', 'C3', 'C4'],
        'D': ['D1', 'D2', 'D3', 'D4']}


source = ColumnDataSource(data)

table = DataTable(height=500, 
                  width=500, 
                  source=source, 
                  row_height=50,
                  columns=[TableColumn(field=col, title=col) for col in data.keys()])

# Align text horisontally (need to do it vertically as well)
for col in table.columns:
    col.formatter.text_align = 'center'
    
show(table)

This produces the following table:

散景数据表

I would like to align the text vertically in the middle of the cells. From what I've seen online I could use HTMLTemplateFormatter to achieve this, but I'm not quite sure how.

It looks like you can set it in the DataTable by the attribute min_height .

table = DataTable(
    ...,
    row_height=50,
    min_height = 45,
)

This looks almost centered. The downside is, that the index column is not effectd.

居中文本

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM