Sessions and Documents

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§) 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§

session=push_session(doc)

session.show()

Output:


<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</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

Hi Marcel,

"figure" (lowecase f) is an an old convenience function that:

* creates a "Figure" (capital F)
* adds it to curdoc

So, replacing "figure" with "Figure" should solve your current problem.

The existence of figure and its automatic behavior are historical, but the usage of "figure" is fairly entrenched. We are still debating the best path forward for the API.

Regards,

Bryan

···

On Jan 14, 2016, at 5:24 PM, Marcel Német <[email protected]> wrote:

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:

---------------------------------------------------------------------------
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

--
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/f472456f-1afd-432a-9118-a3524a76a3db%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

We could make this error message say 'try lowercase "figure" instead of "Figure"' maybe - though there are other ways to get this error that may be the most common one...

···

On Jan 14, 2016, at 6:29 PM, Bryan Van de Ven <[email protected]> wrote:

Hi Marcel,

"figure" (lowecase f) is an an old convenience function that:

* creates a "Figure" (capital F)
* adds it to curdoc

So, replacing "figure" with "Figure" should solve your current problem.

The existence of figure and its automatic behavior are historical, but the usage of "figure" is fairly entrenched. We are still debating the best path forward for the API.

Regards,

Bryan

On Jan 14, 2016, at 5:24 PM, Marcel Német <[email protected]> wrote:

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:

---------------------------------------------------------------------------
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

--
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/f472456f-1afd-432a-9118-a3524a76a3db%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/4D9EDFFA-3E0E-411E-B942-812068793421%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

obviously I meant the other way around for the message :slight_smile:

···

On Jan 14, 2016, at 7:58 PM, Havoc Pennington <[email protected]> wrote:

We could make this error message say 'try lowercase "figure" instead of "Figure"' maybe - though there are other ways to get this error that may be the most common one...

On Jan 14, 2016, at 6:29 PM, Bryan Van de Ven <[email protected]> wrote:

Hi Marcel,

"figure" (lowecase f) is an an old convenience function that:

* creates a "Figure" (capital F)
* adds it to curdoc

So, replacing "figure" with "Figure" should solve your current problem.

The existence of figure and its automatic behavior are historical, but the usage of "figure" is fairly entrenched. We are still debating the best path forward for the API.

Regards,

Bryan

On Jan 14, 2016, at 5:24 PM, Marcel Német <[email protected]> wrote:

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:

---------------------------------------------------------------------------
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

--
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/f472456f-1afd-432a-9118-a3524a76a3db%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/4D9EDFFA-3E0E-411E-B942-812068793421%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thank you, that helped :slight_smile:

Dne pátek 15. ledna 2016 0:29:10 UTC+1 Bryan Van de ven napsal(a):

···

Hi Marcel,

“figure” (lowecase f) is an an old convenience function that:

  • creates a “Figure” (capital F)

  • adds it to curdoc

So, replacing “figure” with “Figure” should solve your current problem.

The existence of figure and its automatic behavior are historical, but the usage of “figure” is fairly entrenched. We are still debating the best path forward for the API.

Regards,

Bryan

On Jan 14, 2016, at 5:24 PM, Marcel Német [email protected] wrote:

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§) 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§

session=push_session(doc)

session.show()

Output:


RuntimeError

                          Traceback (most recent call last)

in ()

----> 1 doc.add_root§

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


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/f472456f-1afd-432a-9118-a3524a76a3db%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.