Flickering and rebuilded plot when adding children to layout

In my current setup with bokeh server I dynamically append plots to a layout. This works but it flickers and temporarily disarranges all the plots so I think all plots are redrawn (or even rebuilt) every time a child is appended to the layout. Is it possible to avoid this flickering and decelarating rebuild?

See this example that demonstrates what I mean:

import numpy as np
from tornado.ioloop import IOLoop

from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.plotting import figure
from bokeh.server.server import Server
from bokeh.models.layouts import VBox

io_loop = IOLoop.current()
layout = VBox()

def modify_doc(doc):
    doc.add_root(layout)
    doc.add_periodic_callback(add_plot, 5000)

def add_plot():
    x = np.linspace(0, 4 * np.pi, 1000)
    y = np.sin(x)
    plot2 = figure(y_range=(-1.2, 1.2))
    plot2.line(x, y, line_width=2, legend="x")
    layout.children.append(plot2)

bokeh_app = Application(FunctionHandler(modify_doc))
server = Server({'/': bokeh_app}, io_loop=io_loop)
server.start()

if __name__ == '__main__':
    print('Opening Bokeh application on http://localhost:5006/')
    io_loop.add_callback(server.show, "/")
    io_loop.start()

``

Hi,

At present, probably not. Global coordinates are computed for all objects in a layout, and adding a new item means re-computing the layout for everything (which means re-drawing). There is an open issue to allow individual elements from a Bokeh server app to be templated individually (i.e they don't share layout state with other objects) which would probably solve the problem at the expense of having to do something a little more involved than layout.children.append to add new plots to the page.

FYI this example is broken in master. I've created an issue for the regression

  https://github.com/bokeh/bokeh/issues/6213

We are currently performing a major overhaul of all the layout code, so I expect there to be a period where problems shake out.

Thanks,

Bryan

···

On Apr 28, 2017, at 09:34, [email protected] wrote:

In my current setup with bokeh server I dynamically append plots to a layout. This works but it flickers and temporarily disarranges all the plots so I think all plots are redrawn (or even rebuilt) every time a child is appended to the layout. Is it possible to avoid this flickering and decelarating rebuild?

See this example that demonstrates what I mean:

import numpy as np
from tornado.ioloop import IOLoop

from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.plotting import figure
from bokeh.server.server import Server
from bokeh.models.layouts import VBox

io_loop = IOLoop.current()
layout = VBox()

def modify_doc(doc):
    doc.add_root(layout)
    doc.add_periodic_callback(add_plot, 5000)

def add_plot():
    x = np.linspace(0, 4 * np.pi, 1000)
    y = np.sin(x)
    plot2 = figure(y_range=(-1.2, 1.2))
    plot2.line(x, y, line_width=2, legend="x")
    layout.children.append(plot2)

bokeh_app = Application(FunctionHandler(modify_doc))
server = Server({'/': bokeh_app}, io_loop=io_loop)
server.start()

if __name__ == '__main__':
    print('Opening Bokeh application on http://localhost:5006/'\)
    io_loop.add_callback(server.show, "/")
    io_loop.start()

--
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/352b31ed-1a7d-4a57-a52d-557a5f12e11a%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks, Bryan. I guess I’ll try to manage a bit of dynamic layout with JS/CSS. Individual templates sound very good, I would not mind the additional expense then. Do you mean this issue: Allow elements to be placed in server templates · Issue #4986 · bokeh/bokeh · GitHub?

And thank you for the regression check.