☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Assign a python variable to a bokeh template

Community Supportbokeh
Thinh_Nguyen
Thinh_Nguyen

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))
            {return("LightGrey")}
        else
            {return("Black")}
    }()) %>; 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])) 
                {return("LightGreen")}
            else
                {return("White")}
    }()) %>;">
    <%= (value).toFixed(2) %></div>"""
⌁   Link to post

End of archived discussion · Replies are disabled