Assign a python variable to a bokeh template

Hi All,
I have a python list called vitamin_list and I created a bokeh template, which I want to use to format a DataTable column. The idea is that if a column in the table called ‘nutr_name’ contains any of the item in the vitamin_list, the column on which I apply the template (via formatter) should be formatted accordingly.
I do not have any knowledge in javascript but I searched around + ChatGPT and managed to come up with the code below. But it just doesn’t run properly. I think the main thing is how can I assign a python variable to the code block below.
Could someone please help me? Many thanks in advance.

template3 = """<div style="word-wrap: normal; color:<%=
    (function colorfromint(){
        if (isNaN(value))
    }()) %>; background-color:<%=
    (function colorfromint(){
        var vitamin_list = {vitamin_list};
        for (var i = 0; i < vitamin_list.length; i++) {
            if (data.nutr_name.includes(vitamin_list[i])) 
    }()) %>;">
    <%= (value).toFixed(2) %></div>"""

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.