简体   繁体   English

如何基于另一个列值格式化bokeh DataTable单元格?

[英]How to format a bokeh DataTable cell based on another column value?

Salutations. 拜。

I am developing an application using bokeh server (version 0.12.13) and I have a DataTable widget with several columns. 我正在使用bokeh服务器(版本0.12.13)开发应用程序,并且我有一个带有几列的DataTable小部件。 One of them are a measure of an issue open days and another is an estimate of days to close such issue. 其中之一是对问题开放天数的度量,而另一个是对完成该问题的天数的估计。

In some situations, the amount of days that an issue is open surpasses the estimated amount and I would like to colour the estimated days column red if that happens. 在某些情况下,未解决问题的天数超过了估计的天数,如果发生这种情况,我想将估计的天数列涂成红色。

I have tried using "widget.HTMLTemplateFormatter", but I haven't figured out how to access another column value to make the comparison and decide whether paint the cell red or not. 我尝试使用“ widget.HTMLTemplateFormatter”,但是我还没有弄清楚如何访问另一个列值进行比较并确定是否将单元格涂成红色。

Does anyone know how to get around this? 有谁知道如何解决这个问题?

You can either define a javascript function within the underscore js code to conditionally color each cell. 您可以在下划线js代码中定义javascript函数,以有条件地为每个单元格着色。 Each of the fields within the data source linked to the table can be accessed. 可以访问链接到表的数据源中的每个字段。

from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, TableColumn, HTMLTemplateFormatter
from bokeh.io import show

dict1 = {'estd':[1]*6,
         'actd':[1, 1, 1, 2, 2, 2],
         'z'   :[3, 3, 3, 3, 3, 3]}

source = ColumnDataSource(data=dict1)

template="""
<b><div style="background:<%= 
    (function colorfromint(){
        if(actd > estd){
            return("Red")
        }
        else{
            return("White")
        }
     }()) %>;">
<%= (value).toFixed(1) %></div></b>
"""

formater =  HTMLTemplateFormatter(template=template)
columns = [
    TableColumn(field="estd", title="Estimated Days"),
    TableColumn(field="actd", title="Actual days",formatter=formater),
    TableColumn(field="z", title="z")
]

data_table = DataTable(source=source, columns=columns, width=800)

show(data_table)

If the data does not change you can define the colors using python code, see the second example here: How do I adjust number format in bokeh data table using HTMLTemplateFormatter? 如果数据不变,则可以使用python代码定义颜色,请参见此处的第二个示例: 如何使用HTMLTemplateFormatter调整bokeh数据表中的数字格式? .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 列中的条件格式单元格基于它在另一列中的对应值 - Conditional format cell in column based on it corresponding value in another column 如何在点击时获取Bokeh DataTable单元格内容? - How to get Bokeh DataTable cell content on click? Bokeh DataTable 颜色单元格基于每个单元格的不同范围 - Bokeh DataTable color cells based on different range for each cell Python Pandas 根据另一个单元格中的值检查列中的单元格值 - Python Pandas check cell value in column based on value in another cell 如何向前填充 dataframe 列,其中填充的行数限制基于另一列中单元格的值? - How can I forward fill a dataframe column where the limit of rows filled is based on the value of a cell in another column? Pandas:根据 groupby sum 结果与另一列中的值的比较来修改每组中最后一个单元格的值 - Pandas: Modify the value of last cell in each group based on how the groupby sum result compares to the value in another column 我如何根据列单元格值和 append 查找一个 dataframe 上的一行到另一个 dataframe 上的一行? - How do i lookup a row on one dataframe based on the column cell value and append that to a row on another dataframe? Python:根据另一列中的值提取单元格值 - Python: Extracting cell values based on value in another column 具有一列可编辑列的散景数据表 - Bokeh DataTable with one editable column 散景中的数据表 - 如何隐藏索引列? - DataTable in Bokeh - How do you hide the index column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM