some dynamic add/remove tests
This commit is contained in:
38
prototypes/dyn1.py
Normal file
38
prototypes/dyn1.py
Normal file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from bokeh.layouts import column#, layout
|
||||
from bokeh.models import Button, ColumnDataSource
|
||||
from bokeh.models.widgets import Div, Panel, Tabs
|
||||
from bokeh.plotting import curdoc
|
||||
from bokeh.plotting import figure
|
||||
|
||||
def add_button():
|
||||
print("adding")
|
||||
|
||||
data = {
|
||||
"x": [0, 1, 2],
|
||||
"y": [2, 0, 1]
|
||||
}
|
||||
source = ColumnDataSource(data=data)
|
||||
|
||||
fig = figure()
|
||||
fig.step(x="x", y="y", source=source, mode="after")
|
||||
fig.circle(x="x", y="y", source=source)
|
||||
pan = Panel(child=fig, title="test", closable=True)
|
||||
tab = [pan]
|
||||
|
||||
size = 25
|
||||
height, width = fig.height, fig.width
|
||||
btn = Button(label="X", button_type="danger", margin=(-height+size, 0, 0, width-size), width=0, height=0, width_policy="fixed", height_policy="fixed")
|
||||
|
||||
layout.children.append(Tabs(tabs=tab))
|
||||
layout.children.append(btn)
|
||||
|
||||
|
||||
button = Button(label="Click to add", button_type="success")
|
||||
button.on_click(add_button)
|
||||
layout = column(button)
|
||||
curdoc().add_root(layout)
|
||||
|
||||
|
||||
|
55
prototypes/dyn2.py
Normal file
55
prototypes/dyn2.py
Normal file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import numpy as np
|
||||
from bokeh.layouts import row, column#, layout
|
||||
from bokeh.models import Button, ColumnDataSource
|
||||
from bokeh.models import Spacer
|
||||
from bokeh.models.widgets import Div, Panel, Tabs
|
||||
from bokeh.plotting import curdoc
|
||||
from bokeh.plotting import figure
|
||||
|
||||
|
||||
def add_button():
|
||||
print("adding")
|
||||
|
||||
btn = Button(label="🗙", button_type="light", width=35)
|
||||
|
||||
lbl = Div(text="A test plot", align="center", style={"font-size": "150%"})
|
||||
|
||||
data = {
|
||||
"x": [0, 1, 2],
|
||||
"y": np.random.random((3,))
|
||||
}
|
||||
source = ColumnDataSource(data=data)
|
||||
|
||||
fig = figure()
|
||||
fig.step(x="x", y="y", source=source, mode="after")
|
||||
fig.circle(x="x", y="y", source=source)
|
||||
|
||||
combo = column(row(btn, lbl), fig, Spacer(height=35))
|
||||
btn.on_click(lambda: remove_button(combo))
|
||||
|
||||
layout.children.append(combo)
|
||||
|
||||
|
||||
|
||||
def remove_button(which):
|
||||
print("removing", which)
|
||||
layout.children.remove(which)
|
||||
|
||||
|
||||
|
||||
button = Button(label="Click to add", button_type="success")
|
||||
#button0 = Button(label="Click to add", button_type="default")
|
||||
#button1 = Button(label="Click to add", button_type="primary")
|
||||
#button2 = Button(label="Click to add", button_type="success")
|
||||
#button3 = Button(label="Click to add", button_type="warning")
|
||||
#button4 = Button(label="Click to add", button_type="danger")
|
||||
#button5 = Button(label="Click to add", button_type="light")
|
||||
|
||||
button.on_click(add_button)
|
||||
layout = column(button)#, button0, button1, button2, button3, button4, button5)
|
||||
curdoc().add_root(layout)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user