[英]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.