Hello gentlemen,
is it possible to update the layout of figures arranged in a gridplot at runtime? Basically I want to reorder figures by swapping positions of two figures using a button callback. But whatever I try to do it does not work as expected.
Here is a minimal example of what I do consider one of my best tries:
from bokeh.application.handlers.function import FunctionHandler
from bokeh.application import Application
from bokeh.document import Document
from bokeh.server.server import Server
from bokeh.plotting import figure, output_file, show, gridplot
from bokeh.models import GridBox
from bokeh.layouts import column, grid
from bokeh.models.widgets import Button
model = None
def on_button():
f1, f2, b = model.children[1].children
# swap items - but no effect
model.children[1].children = [f2, f1, b]
def make_document(doc: Document):
global model
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
p.line(x, y, legend="Temp.", line_width=2)
y2 = [3, 5, 2, 11, 9]
p2 = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
p2.line(x, y2, legend="Temp.", line_width=2)
b = Button(label="Rearrange", button_type="success")
b.on_click(on_button)
model = gridplot(children=[[p], [p2], [b]])
doc.add_root(model)
handler = FunctionHandler(make_document)
app = Application(handler, )
apps = {'/': app}
server = Server(apps, port=80)
server.run_until_shutdown()
But it has no visible effect. I suspect it is quite easy to do probably but I just can’t manage to do the right thing. A bit of help would be very appreciated.
I am using Bokeh 1.4.0 from Miniconda on Windows 10 x64.
Thanks alot!