I want to color the text of a specific row in a DataTable in Bokeh. The color should depend on the entry in color array (Like for example when using a graph in bokeh)
I set up my code like this:
source = ColumnDataSource(data=dict(
neighbors=[],
words=[],
ref_fragments=[],
closest=[],
distances=[],
color=[]
))
columns = [TableColumn(field='neighbors', title='Neighbor Fragment', width=100),
TableColumn(field='words', title='Word', width=100),
TableColumn(field='ref_fragments', title='Reference Fragment', width=100),
TableColumn(field='closest', title='Closest Words', width=200),
TableColumn(field='distances', title='Distances', width=300)]
table = DataTable(source=source, columns=columns, width=800, height=800)
The source will be filled during runtime interaction. When using a graph in bokeh it would be easy to simply use the 'color' attribute in the source to color points accordingly. Sadly this does not work with DataTables.
A question and answer on Stackoverflow (https://stackoverflow.com/a/51048558/3220400)
template="""
<p style="color:<%=
(function colorfromarry(){
//HERE CODE THAT SETS COLOR SPECIFIC TO THE ENTRY IN THE COLOR ENTRY OF ITS ROW
}()) %>;">
<%= value %>
</p>
"""
formatter = HTMLTemplateFormatter(template=template)
and then I can use the formatter on the specific column. In my case I would assume I have to use the same formatter on each column? My question is, how to set the colorfromarry function, so that each entry in the row gets a color specific to the entry in the array (e.g. row i looks at color[i])?