Search code examples
pythonthemesbokeh

Specifying default bokeh toolbar behaviour in theme


Is it possible to write a theme for bokeh such that, e.g. the drag tool and the zoom wheel tool are active by default? I know how to set these active by accessing the properties of the figure, but I'd like to put all the default stuff that I want to use for all my plots in the theme.

I've looked through the documentation for themes and the documentation for the toolbar but haven't come up with a solution. The only thing I was able to find is how to deactivate a tool by default, e.g.

{
    'attrs': {
        'Toolbar': {
            'active_scroll': None
        }
     }
}

Is this possible via theme or am I out of luck?


Solution

  • It's not possible because all the active_* properties of Toolbar must be set either to "auto" (which sounds like something you don't want) or to the desired tool instance. And you cannot put an instance into JSON.

    You could maybe write a theme JSON preprocessor that would accept a toolbar and that would set the relevant tool instances. But even if that's possible, it has at least two downsides:

    1. You will have to set the theme after the toolbar is created and populated
    2. You cannot share the theme between documents or apply the theme to a document with multiple toolbars