1

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:

Bokeh DataTable

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.

JM Nel
  • 53
  • 1
  • 5

1 Answers1

1

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.

centerd text

mosc9575
  • 5,618
  • 2
  • 9
  • 32