Bokeh Tabs

Currently I have code that generates different tabs in Bokeh, like this:

tab1 = Panel(child=grid1, title=“tab1”)

tab2= Panel(child=grid2, title=“tab2”)

tabs = Tabs(tabs=[tab1, tab2])

show(tabs)

where grid1 and grid2 are gridplot objects, created by code that looks like this

plots =

while

p = Figure(…)

plots.append([p])

grid1 = gridplot(plots)

This produces tabs with just the grids of these figures.

However, what I’d really like to be able to do is for each tab to contain a mix of different widgets - such as Figures, Text, Tables etc - and not just Figures as in the example above.

After looking through the documentation, it seems like the Panel(child=…) doesnt allow for defining a mix of different types of widgets. I hope I’m wrong and there is actually indeed a way to make each tab contain a mix of different widgets.

If anyone knows about this, and is able to provide any pointers or examples, it would be greatly appreciated.

Thanks in advance!

Hi,

You can use Rows or Columns to group things together in tabs. This lets you build quite complex layouts. There’s a simple example below: two tabs each containing a plot and two widgets.

Hope that helps,
Marcus.

from bokeh.plotting import Figure
from bokeh.models.widgets import Div, CheckboxGroup, Slider
from bokeh.models.widgets.panels import Panel, Tabs
from bokeh.models.layouts import Column
from bokeh.io import show

x = list(range(-5, 6))

width, height = 300, 300
fig1 = Figure(plot_width=width, plot_height=height)
fig2 = Figure(plot_width=width, plot_height=height)

fig1.line(x, x, color=‘blue’)

y = [xe**2 for xe in x]
fig2.line(x, y, color=‘red’)

cbg = CheckboxGroup(labels=[‘First’, ‘Second’, ‘Third’], active=[0])
sldr = Slider(start=0, end=1, step=0.1)

panel1 = Panel(title=‘Straight line’,
child=Column(fig1,
Div(text=‘Plot of y=x’),
cbg))
panel2 = Panel(title=‘Parabola’,
child=Column(fig2,
Div(text=‘Plot of y=x2’),
sldr))

tabs = Tabs(tabs=[panel1, panel2])
show(tabs)

``