【问题标题】:Bokeh won't show string linebreaks in DatatableBokeh 不会在 Datatable 中显示字符串换行符
【发布时间】:2016-06-27 05:30:25
【问题描述】:

我正在尝试使用 Bokeh 显示字符串表(我已经在 vplot+tabs 中使用散景图,并且想要在 vplot 中也有一个数据表)。

我的字符串是多行的,因为有 '\n' 字符,但是当尝试在 Bokeh DataTable 中显示这些字符时,换行符会被删除。有什么办法可以避免这种情况?

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))    

这会产生以下结果:

(注意:此示例代码也在https://github.com/seltzered/Bokeh-multiline-datatable-demo

环境:Python 3.5、Jupyter 1.0 / Notebook 4.1.0、散景 0.11.1

小更新:尚未解决,但意识到 table/slickgrid 的 web 布局似乎为后面的行设置了硬高度值(25px/行)和偏移量,所以我认为这是一个预期的限制。

【问题讨论】:

  • 只是为了澄清我的示例:我不希望该示例中的数据有单独的行单元格(这可以通过传入实际数组而不是格式化字符串来解决) - 我'我只是在寻找出现的换行符。

标签: jupyter bokeh


【解决方案1】:

我尝试使用 HTMLTemplateFormatter,但遇到了您提到的相同问题。这只会显示每个数组的第一行:

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))

【讨论】:

    【解决方案2】:

    问题似乎不是由散景引起的,它更多的是 slickgrid 的限制 - 那里发布了一些解决方法/slickgrid forks,供那些真正寻找具有多线网格的解决方案的人使用,但还没有看到任何东西正式并入。

    查看 slickgrid 的相关问题:Is variable rowheight a possibility in SlickGrid?

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

    【讨论】:

      猜你喜欢
      • 2020-03-02
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多