Python Bokeh table columns and headers do not line up

I am trying to display a table in a jupyter laptop using python and the Bokeh visualization library. I use the following code to display my table in a jupyter laptop, where result is a dataframe:

source = ColumnDataSource(result) columns = [ TableColumn(field="ts", title="Timestamp"), TableColumn(field="bid_qty", title="Bid Quantity"), TableColumn(field="bid_prc", title="Bid Price"), TableColumn(field="ask_prc", title="Ask Price"), TableColumn(field="ask_qty", title="Ask Quantity"), ] data_table = DataTable(source=source, columns=columns, fit_columns=True, width=1300, height=800) show(widgetbox([data_table], sizing_mode = 'scale_both')) 

I used to use vform, although now it seems to be depreciated and no longer works as expected. This happened after updating my version of jupyter laptop. Regardless of the fact that I set the width, the column headings do not line up and have a strange coincidence with the table:

enter image description here

This was not before, I was able to get a good table where everything was lined up. Even if I customize the headers, they still don't line up. This does not happen when I save the table as an html file instead of calling show () directly in a Jupyter laptop. What do i need to change? Is there a better way to do this?

Full example

 from bokeh.io import show, output_notebook from bokeh.layouts import widgetbox from bokeh.models import ColumnDataSource from bokeh.models.widgets import TableColumn, DataTable import pandas as pd output_notebook() d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']), 'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])} df = pd.DataFrame(d) source = ColumnDataSource(df) columns = [ TableColumn(field="one", title="One"), TableColumn(field="two", title=" Two"), ] data_table = DataTable(source=source, columns=columns, fit_columns=True, width=800, height=800) show(widgetbox([data_table], sizing_mode = 'scale_both')) 

This works on a system with the following versions:

  • Jupyter 4.2.0
  • Python 2.7.12 (Anaconda 2.3.0 64 bit)
  • Bokeh 0.12.2
+8
python ipython jupyter bokeh
source share
1 answer

The css-style of Jupyter's Bokeh widgets for laptops is at http://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.0.min.css , where height:16px for .bk-root .bk-slick-header-column.bk-ui-state-default elements .bk-root .bk-slick-header-column.bk-ui-state-default hard-coded. Therefore, it cannot be changed without changing css.

It could be adhock style with HTML function

 from IPython.core.display import HTML HTML(""" <style> .bk-root .bk-slick-header-column.bk-ui-state-default { height: 25px!important; } </style> """) 

To constantly change css, you can add it to the custom directory in the Jupyter configuration. You can find out exactly where by calling

 jupyter --config-dir 

By default it is ~/.jupyter new css should be in ~/.jupyter/custom/custom.css then.

Before enter image description here

After enter image description here

+2
source share

All Articles