0

I'm trying to show a table of strings using Bokeh (I'm already using bokeh plots within a vplot+tabs, and wanted a table of data also in the vplot).

My strings are multiline via having '\n' characters, but when attempting to display these within a Bokeh DataTable the line breaks are stripped. Any way to avoid this?

Example code in a jupyter python3 notebook:

import bokeh
from bokeh.plotting import figure, output_notebook, show, vplot
from bokeh.io import output_file, show, vform
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, StringFormatter, TableColumn

output_notebook()


table_data = ColumnDataSource(dict(strings=['[ -1.23456, \n \
7.89012, \n \
3.456789 \n \
 ]', \
   '[ -1.23456, \n \
7.89012, \n \
3.456789 \n \
 ]'] 
))
columns = [TableColumn(field="strings", title="Strings", formatter=StringFormatter(text_color='#BB0000')) ]
tableplot = DataTable(source=table_data, columns=columns)

show(vform(tableplot))    

This yields in the following: enter image description here

(note: this example code is also at https://github.com/seltzered/Bokeh-multiline-datatable-demo

Environment: Python 3.5, Jupyter 1.0 / Notebook 4.1.0, bokeh 0.11.1

Small update: not solved yet, but realized that the web layout for the table/slickgrid seems to set hard height values (of 25px/line) and offsets for later rows, so I'm thinking this is an expected limitation.

Vivek Gani
  • 1,283
  • 14
  • 28
  • just to clarify my example: I don't want separate row cells for the data in that example (that can be solved by just passing the actual array in rather than a formatted string of it) - I'm just looking for linebreaks to appear. – Vivek Gani Mar 11 '16 at 20:23

2 Answers2

1

I tried using the HTMLTemplateFormatter but ran into the same issue you mention. This only displays the first line of each array:

table_data = ColumnDataSource(dict(strings=['[ -1.23456, \n \
7.89012, \n \
3.456789 \n \
 ]', \
   '[ -1.23456, \n \
7.89012, \n \
3.456789 \n \
 ]'] 
))
columns = [
    TableColumn(field="strings", 
                title="Strings", 
                formatter=HTMLTemplateFormatter(template='<pre><%= value %></pre>')) ]
tableplot = DataTable(source=table_data, columns=columns)
show(vform(tableplot))
dennisobrien
  • 1,148
  • 13
  • 7
0

The issue doesn't appear to be due to bokeh, it's more of a limitation of slickgrid - there's some workarounds / slickgrid forks posted out there for those really looking for a solution to have multitline grids, but haven't seen anything officially merged in.

see related questions to slickgrid: Is variable rowheight a possibility in SlickGrid?

https://groups.google.com/forum/#!topic/slickgrid/jvqatSyH-hk

Community
  • 1
  • 1
Vivek Gani
  • 1,283
  • 14
  • 28