Search code examples
pythonbokeh

How to get value of current theme in bokeh?


In bokeh you can set the theme easily:

from bokeh.io import curdoc
curdoc().theme = "caliber"

I am not sure how to simply get a string readout of the current theme. I tried curdoc().theme and that returned <bokeh.themes.theme.Theme at 0x21637f022c8>. Just using printing, __repr__, and __str__ returned similar results. Simply inspecting the output of dir(curdoc().theme) didn't reveal any obvious getters I might try (but I'm probably missing something obvious).


Solution

  • Theme does not contain that information, but you could try:

    from bokeh.themes import built_in_themes
    
    theme = curdoc().theme
    theme_name = next(k for k, v in built_in_themes.items() if v is theme)