Skip to content

Instantly share code, notes, and snippets.

@mattpap
Created March 30, 2018 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpap/70544bd158ecec52f69a014a6aeb05fd to your computer and use it in GitHub Desktop.
Save mattpap/70544bd158ecec52f69a014a6aeb05fd to your computer and use it in GitHub Desktop.
Cycle bokeh's tabs with CustomJS
from bokeh.io import save
from bokeh.plotting import figure
from bokeh.layouts import column
from bokeh.models import CustomJS
from bokeh.models.widgets import Button, Tabs, Panel
def make_tab(color):
p = figure()
p.scatter([0], [0], color=color, radius=1)
return Panel(title="Tab: %s" % color.capitalize(), child=p)
red = make_tab("red")
green = make_tab("green")
blue = make_tab("blue")
tabs = Tabs(tabs=[red, green, blue])
next_tab = CustomJS(args=dict(tabs=tabs), code="""
tabs.active = (tabs.active + 1) % tabs.tabs.length
""")
button = Button(label="Next tab", callback=next_tab)
save(column(button, tabs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment