Wrapping Text in DataTable Cell

Hey guys,

I was just wondering if there is a way to wrap text in a DataTable cell? Also is there a way to apply custom html (with variable referencing) to the cells? I was thinking something like the HoverTools tooltip?

Thanks for the info!

Please see:

  http://bokeh.pydata.org/en/latest/docs/reference/models/widgets.tables.html#bokeh.models.widgets.tables.HTMLTemplateFormatter

Thanks,

Bryan

···

On Jun 6, 2017, at 11:18, [email protected] wrote:

Hey guys,

I was just wondering if there is a way to wrap text in a DataTable cell? Also is there a way to apply custom html (with variable referencing) to the cells? I was thinking something like the HoverTools tooltip?

Thanks for the info!

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/50e68d8f-49ea-40e5-ba2a-8391338598f9%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the link above. I have been playing around with the HTMLTemplateFormatter but have been unable to wrap the text in my TableColumn; my code is below. Does anyone have the requisite syntax? I’m sorry if I’m missing smth obvious, but I have started using Bokeh only recently and have no experience when it comes to HTML.

formatter = HTMLTemplateFormatter(
template="""

{whiteSpace: ‘normal’, wordWrap: ‘break-word’}

<%= value %>"""
)

Interested in this too.

FWIW I wrestled with this for a while last night and could not figure out the correct syntax to implement this ( I want to know how to do this as well!).

Working example below:

from bokeh.plotting import output_file, show
from bokeh.models.widgets import DataTable, TableColumn,HTMLTemplateFormatter
from bokeh.models import ColumnDataSource
output_file('table_test.html')
#TABLE of calib stats
tcols = ['Longass string I want to wrap stuff arount','Column 2 that is also really long winded']

#can't figure out how to get text to wrap in tables gahh
wrap_fmt = HTMLTemplateFormatter(template="""<span style='word-break: break-all;'> <%=value %></span>""")
#tried...
# wrap_fmt = HTMLTemplateFormatter(template="""<table style='word-break: break-all;'%> <%=value %></table>""")
# wrap_fmt = HTMLTemplateFormatter(template="""<div style='word-break: break-all;'> <%=value %></div>""")
# wrap_fmt = HTMLTemplateFormatter(template="""<td style='word-break: break-all;'> <%=value %></td>""")

tbl_cols = [TableColumn(field=c,title=c
                        ,formatter=wrap_fmt
                        ) for c in tcols]

content = {tcols[0]:['Another longass string I want to wrap too','Some more content']
           ,tcols[1]:['Another longass string I want to wrap too','Some more content in Column 2']}
cstats_tbl = DataTable(columns=tbl_cols,source=ColumnDataSource(content)
                       ,height=500,width=200)
show(cstats_tbl)

I tried more than just what’s in the code above… - attempted using ‘word-wrap:break-word’ etc. My gut feeling is that I don’t understand how underscore js works to make “templates”, and the syntax behind telling that template to make my cells formatted the way I want them to be.

I inspected the html output of this code and found this… so my template instructions are being embedded here…

{"attributes":{"template":"&lt;table style='word-break: break-all;'&gt; &lt;%=value %&gt;&lt;/table&gt;"}

Any help from those with a better understanding of undscore js and how HTMLTemplateFormatter harnesses it much appreciated… thanks…