How to change from one Bokeh tab to another Bokeh tab by clicking a button?

I want to move from one Bokeh tab to another Bokeh tab(not browser tab) by clicking a Bokeh Button.

The question is if I can use OpenURL and how can I point to the new tab? Something like my_button.on_click(OpenURL()) .

Visually, the desired action is shown here:

Cheers,

Hi,

···

On Thu, Mar 29, 2018 at 7:04 PM, Ionel Miu [email protected] wrote:

I want to move from one Bokeh tab to another Bokeh tab(not browser tab) by clicking a Bokeh Button.

The question is if I can use OpenURL and how can I point to the new tab? Something like my_button.on_click(OpenURL()) .

it’s not possible with OpenURL, because tabs don’t have anchors (we use data attributes instead). However, one could use CustomJS to achieve this:

next_tab = CustomJS(args=dict(tabs=tabs), code=“”"

tabs.active = (tabs.active + 1) % tabs.tabs.length

“”")

(full example at https://gist.github.com/mattpap/70544bd158ecec52f69a014a6aeb05fd). This has the obvious disadvantage that it requires writing JavaScript. This can be partially mitigated by writing CustomJS in Python (using CustomJS.from_py_func).

Mateusz

Visually, the desired action is shown here:

Cheers,

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5ac95559-76ed-4563-aabe-0b646c75c5e3%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You just need to update the active attribute of the Tabs object. Be it in JS or with the bokeh server

Here is an example with the bokeh server:

from bokeh.models import Tabs, Panel, Button, Div
from bokeh.io import curdoc
from bokeh.layouts import Column

button = Button(label=‘next tab’)

tabs=Tabs(tabs=[Panel(title=str(i),child=Div(text=“content of tab {}”.format(i))) for i in range(10)])

def switch_tab():
tabs.active += 1
button.on_click(switch_tab)

curdoc().add_root(Column(button,tabs))

``

And oddly when it reaches 10 it doubles the display of tabs with no errors. But something simple could easily be done in the callback to stay within the existing number of tabs