This is something (usage of classes in bokeh plots) I’ve started practicing recently. Although I can’t share the entire code at this point, my structure is similar as below.
def plot_format(self, plot):
format plot like background_fill_color, border_fill_color..
Instead of repeating it in multiple places.
""" Create all the necessary plots"""
# To format plots
self.fig_name = self.plot_format(self.fig_name)
# I return a panel object here but it could be anything like a figure.
Define all variables that are used across multiple classes, so that you don't have
to do it in every other class.
tab_1 = self.exploration_plots() # function from class plots to create panel_1
tabs = Tabs(tabs=[tab_1], tabs_location='above')
tabs = main().run_classes()
curdoc().title = "Bokeh Server App"
In my case, this has reduced the size of code and made the process easier for keeping track of variables.
For example, in my case there are 6 tabs and each tab would have least 3-4 plots, 4-5 widgets and 2-3 data sources, all interacting between them and with other libraries like sklearn and scipy. Compared to the first version (keeping all variables in global scope) of code, this method is better in my case.