I am able to dynamically add tabs. Script is below. I am not sure how to delete tabs though.
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox,column
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Slider, TextInput, Button
from bokeh.plotting import figure
from bokeh.models.widgets import Tabs
from bokeh.models.widgets import Panel
TABS_LIST =
TABS = Tabs(tabs=TABS_LIST)
def create_slider_tab():
N = 200
x = np.linspace(0, 4*np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
Set up plot
plot = figure(plot_height=400, plot_width=400, title=“my sine wave”,
tools=“crosshair,pan,reset,save,wheel_zoom”,
x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])
plot.line(‘x’, ‘y’, source=source, line_width=3, line_alpha=0.6)
Set up widgets
text = TextInput(title=“title”, value=‘my sine wave’)
offset = Slider(title=“offset”, value=0.0, start=-5.0, end=5.0, step=0.1)
amplitude = Slider(title=“amplitude”, value=1.0, start=-5.0, end=5.0)
phase = Slider(title=“phase”, value=0.0, start=0.0, end=2*np.pi)
freq = Slider(title=“frequency”, value=1.0, start=0.1, end=5.1)
Set up callbacks
def update_title(attrname, old, new):
plot.title.text = text.value
text.on_change(‘value’, update_title)
def update_data(attrname, old, new):
Get the current slider values
a = amplitude.value
b = offset.value
w = phase.value
k = freq.value
Generate the new curve
x = np.linspace(0, 4*np.pi, N)
y = anp.sin(kx + w) + b
source.data = dict(x=x, y=y)
for w in [offset, amplitude, phase, freq]:
w.on_change(‘value’, update_data)
Set up layouts and add to document
inputs = widgetbox(text, offset, amplitude, phase, freq)
tab_layout = column(row(inputs, plot, width=800))
tab = Panel(child=tab_layout, title=“Sliders”)
TABS_LIST.append(tab)
TABS.update(tabs=TABS_LIST)
def select_click():
create_slider_tab()
button = Button(label=“Select”)
button.on_click(select_click)
main_tab_layout = column(row(button))
tab = Panel(child=main_tab_layout, title=“Main”)
TABS_LIST.append(tab)
TABS.update(tabs=TABS_LIST)
curdoc().add_root(TABS)
curdoc().title = “Sliders”
···
On Friday, October 21, 2016 at 12:11:40 PM UTC-5, Bryan Van de ven wrote:
Running your code I see an error in the browser JS console:
[bokeh] – "Error handling message: TypeError: undefined is not an object (evaluating '[n.id](http://n.id)'), [object MessageEvent]"
But your code looks reasonable at a glance, so this definitely seems like a bug. I’m not sure whether or not there’s an existing issue to cover this (it’s worth a quick search probably). But I’d suggest making a GH bug report or adding a comment to an existing one, with this test case.
Thanks,
Bryan
On Oct 21, 2016, at 12:06 PM, bherman [email protected] wrote:
The following app is in essence what I am trying to do. Every 5 seconds it creates a new Panel and updates the tabs object.
“”"Main module for memory app.
“”"
from future import print_function
import bokeh.client
import bokeh.io
import bokeh.layouts
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
from bokeh.models.tools import BoxSelectTool, BoxZoomTool, HoverTool, \
ResizeTool, ResetTool, WheelZoomTool
DOC = bokeh.io.curdoc()
TABS_LIST =
TABS = bokeh.models.widgets.Tabs(name=‘memory_tabs’, tabs=TABS_LIST)
COUNT = [0]
def add_host_tab():
"""Adds a new tab to figure.
"""
if COUNT[0] > 5:
return
names = ['time', 'memory', 'pid', 'rank', 'host']
source = bokeh.models.ColumnDataSource(data={key: [] for key in names})
tools = [BoxSelectTool(), BoxZoomTool(), ResizeTool(), ResetTool(),
WheelZoomTool()]
plot = bokeh.plotting.figure(tools=tools)
plot.xaxis.axis_label = "Time"
plot.yaxis.axis_label = "Memory [MiB]"
plot.line('time', 'memory', source=source)
layout = bokeh.layouts.row([plot])
TABS_LIST.append(bokeh.models.widgets.Panel(
child=layout, title='HOST{}'.format(COUNT[0])))
print('Making tab HOST{}'.format(COUNT[0]))
TABS.update(tabs=TABS_LIST)
print(TABS.tabs)
COUNT[0] += 1
DOC.add_periodic_callback(add_host_tab, 5000)
DOC.add_root(TABS)
On Friday, October 21, 2016 at 11:23:39 AM UTC-4, Bryan Van de ven wrote:
There seem to stil be some issues specifically around updating layouts to resolve with the server. So you may have run into a but. But it is impossible to speculate without being able to see and run real code. Can you provide a complete, minimal, runnable test case to reproduce the issue you are seeing?
Thanks,
Bryan
On Oct 21, 2016, at 9:12 AM, bherman [email protected] wrote:
I am trying to add Panels dynamically to a Tabs object:
So I first initialize a Tabs object with no panels
Add empty list of tags
DOC = bokeh.io.curdoc()
TABS = bokeh.models.widgets.Tabs(name=‘memory_tabs’, tabs=)
DOC.add_root(TABS)
I have tried to add panels to the TABS object, but they do not render, what is the best way to do this on-the-fly?
Thanks!
–
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/429af7bc-1ef5-4462-a90b-4c72771ee397%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
–
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/6c295d0d-d7db-4cfc-87c6-bb0c4215360e%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.