I started playing with sessions and documents.
I start the server with NO script.
I believe that creating document on client using e.g.
doc=Document()
has no meaning, since all the future figures are automatically added to current document (that can be referenced by curdoc() ).
I crate a figure,that is automatically added to curdoc()
Then I can push_session(curdoc())
and I can do this multiple times to obtain multiple sessions to the same document.
This if I understand separates the “state” of the document, so if one user zooms, selects or even changes the data of the plot, the user with the other session is not affected.
But I failed to create multiple documents, e.g. user 1 has document 1 with figures A, B, and user 2 is connected to document 2 with figures C,D.
I.e. all the plots are accessible to all the users, because all users share the same initial setting of a document?
I can push a new document created by doc=Document(), but in no way can I assign figures to such document, because all newly created figures are automatically assigned to curdoc(). And when I try to do so (doc.add_root(p)) I get:
Code:
import numpy as np
from numpy import pi
from bokeh.client import push_session,pull_session
from bokeh.driving import cosine
from bokeh.plotting import figure, curdoc
from bokeh.document import Document
doc=Document()
x = np.linspace(0, 10*pi, 80)
y = np.log(x)
p = figure()
r1 = p.line([0, 4*pi], [-1, 1], color=“firebrick”)
r2 = p.line(x, y, color=“red”, line_width=4)
doc.add_root(p)
session=push_session(doc)
session.show()
Output:
<details class='elided'>
<summary title='Show trimmed content'>···</summary>
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-37-c596a10d4a4e> in <module>()
----> 1 doc.add_root(p)
C:\Users\nem\AppData\Local\Continuum\Anaconda2\lib\site-packages\bokeh\document.pyc in add_root(self, model)
344 self._roots.append(model)
345 finally:
--> 346 self._pop_all_models_freeze()
347 self._trigger_on_change(RootAddedEvent(self, model))
348
C:\Users\nem\AppData\Local\Continuum\Anaconda2\lib\site-packages\bokeh\document.pyc in _pop_all_models_freeze(self)
264 self._all_models_freeze_count -= 1
265 if self._all_models_freeze_count == 0:
--> 266 self._recompute_all_models()
267
268 def _invalidate_all_models(self):
C:\Users\nem\AppData\Local\Continuum\Anaconda2\lib\site-packages\bokeh\document.pyc in _recompute_all_models(self)
288 d._detach_document()
289 for a in to_attach:
--> 290 a._attach_document(self)
291 self._all_models = recomputed
292 self._all_models_by_name = recomputed_by_name
C:\Users\nem\AppData\Local\Continuum\Anaconda2\lib\site-packages\bokeh\model.pyc in _attach_document(self, doc)
81 '''This should only be called by the Document implementation to set the document field'''
82 if self._document is not None and self._document is not doc:
---> 83 raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self))
84 self._document = doc
85 doc.theme.apply_to_model(self)
RuntimeError: Models must be owned by only a single document, <bokeh.models.formatters.BasicTickFormatter object at 0x000000000C565048> is already in a doc