Hi Bryan,
I think this is a bokeh app in the server, not using the bokeh.client API. A more minimal example of the problem that I’m facing is below.
from bokeh.plotting import Figure
from bokeh.models.layouts import VBox
from bokeh.models.widgets import RadioGroup
import bokeh.io as io
fig1 = Figure()
fig1.circle(x=[1,2], y=[3,4])
fig2 = Figure()
fig2.circle(x=[100,200], y=[200, 1000])
def switch_plots(selected_plot):
io.curdoc().clear()
print(io.curdoc().roots)
#print(io._state.session_id)
io.curdoc().add_root(layouts[selected_plot])
io.curdoc().add_root(layout_picker)
print(io.curdoc().roots)
io.push()
layout_picker = RadioGroup(labels=[‘Layout1’, ‘Layout2’])
layout_picker.on_click(switch_plots)
layout1 = VBox(children=[fig1])
layout2 = VBox(children=[fig2])
layouts = [layout1, layout2]
io.curdoc().add_root(layout1)
io.curdoc().add_root(layout_picker)
The full output from running this will be in a P.S. below, but here are the highlights. I run the .py file using bokeh serve. Clicking the radio button clears the document and adds the layout that I want back. But nothing displayed will change, which is why I then tried calling io.push(), but this causes the error that some session_id is None.
2016-03-03 21:07:46,946 Sending pull-doc-reply from session ‘O9nzom7tgeHqLpmUBmceN2ZvxMrxIxcMn0zEPfGLhzhe’
[<bokeh.models.layouts.VBox object at 0x105833290>, <bokeh.models.widgets.groups.RadioGroup object at 0x105833250>]
2016-03-03 21:07:53,256 error handling message Message ‘PATCH-DOC’ (revision 1): AssertionError()
2016-03-03 21:07:53,256 message header {u’msgid’: u’A40B65A85C7343D498D2B64E0649D259’, u’msgtype’: u’PATCH-DOC’} content {u’references’: , u’events’: [{u’new’: 0, u’kind’: u’ModelChanged’, u’model’: {u’type’: u’RadioGroup’, u’id’: u’1057’}, u’attr’: u’active’}]}
Traceback (most recent call last):
…
File “/Users/claire/Documents/test/plots_test.py”, line 19, in switch_plots
io.push()
File “/Users/claire/Documents/bokeh/bokeh/io.py”, line 465, in push
assert session_id is not None
AssertionError
Interestingly, now when I uncomment the print statement that prints out the state’s session_id, I don’t get the same error. Instead it says Running state NOT_YET_CONNECTED? When I first made this post, I think I was still getting the AssertionError, but what I noticed then was that the session ids don’t match, which is shown here too. It seems like the session id for the application is the 6TY… one and the session id on io._state is 7UIp…
2016-03-03 21:14:03,004 Sending pull-doc-reply from session ‘6TYyGlWNb6sK4oKYT5Ve6fppcuwMWZ4YeuYT70MtqcZs’
7UIpi15YVV718UlyNwae2TY8B5b3k8lIllBIOTQ9T4T3
[<bokeh.models.layouts.VBox object at 0x105933290>, <bokeh.models.widgets.groups.RadioGroup object at 0x105933250>]
2016-03-03 21:14:04,518 Running state NOT_YET_CONNECTED
The question is how to get this to work. Or how to get the display to sync with the current document, io.curdoc().
P.S.
Again, this is full output of running the exact code that I posted at the beginning of this message.
(bokeh-dev)ClairesMacBook:test claire$ BOKEH_SIMPLE_IDS=true /users/claire/documents/bokeh/bin/bokeh serve --show plots_test.py
2016-03-03 21:07:45,647 Starting Bokeh server version 0.12.0dev2-3-g6a0d60f
2016-03-03 21:07:45,648 Allowed Host headers: [‘localhost:5006’]
2016-03-03 21:07:45,648 These host origins can connect to the websocket: [‘localhost:5006’]
2016-03-03 21:07:45,648 Patterns are: [(‘/plots_test/?’, <class ‘bokeh.server.views.doc_handler.DocHandler’>, {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x1057a4c90>, ‘bokeh_websocket_path’: ‘/plots_test/ws’}), (‘/plots_test/ws’, <class ‘bokeh.server.views.ws.WSHandler’>, {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x1057a4c90>, ‘bokeh_websocket_path’: ‘/plots_test/ws’}), (‘/plots_test/autoload.js’, <class ‘bokeh.server.views.autoload_js_handler.AutoloadJsHandler’>, {‘application_context’: <bokeh.server.application_context.ApplicationContext object at 0x1057a4c90>, ‘bokeh_websocket_path’: ‘/plots_test/ws’}), (‘/static/(.*)’, <class ‘bokeh.server.views.static_handler.StaticHandler’>)]
2016-03-03 21:07:45,651 Starting Bokeh server on port 5006 with applications at paths [‘/plots_test’]
2016-03-03 21:07:46,274 200 GET /plots_test (::1) 91.07ms
2016-03-03 21:07:46,794 WebSocket connection opened
2016-03-03 21:07:46,794 Receiver created for Protocol(u’1.0’)
2016-03-03 21:07:46,795 ServerHandler created for Protocol(u’1.0’)
2016-03-03 21:07:46,795 ServerConnection created
2016-03-03 21:07:46,946 Sending pull-doc-reply from session ‘O9nzom7tgeHqLpmUBmceN2ZvxMrxIxcMn0zEPfGLhzhe’
[<bokeh.models.layouts.VBox object at 0x105833290>, <bokeh.models.widgets.groups.RadioGroup object at 0x105833250>]
2016-03-03 21:07:53,256 error handling message Message ‘PATCH-DOC’ (revision 1): AssertionError()
2016-03-03 21:07:53,256 message header {u’msgid’: u’A40B65A85C7343D498D2B64E0649D259’, u’msgtype’: u’PATCH-DOC’} content {u’references’: , u’events’: [{u’new’: 0, u’kind’: u’ModelChanged’, u’model’: {u’type’: u’RadioGroup’, u’id’: u’1057’}, u’attr’: u’active’}]}
Traceback (most recent call last):
File “/Users/claire/Documents/bokeh/bokeh/server/protocol/server_handler.py”, line 38, in handle
work = yield handler(message, connection)
File “//anaconda/envs/bokeh-dev/lib/python2.7/site-packages/tornado/gen.py”, line 1008, in run
value = future.result()
File “//anaconda/envs/bokeh-dev/lib/python2.7/site-packages/tornado/concurrent.py”, line 232, in result
raise_exc_info(self._exc_info)
File “//anaconda/envs/bokeh-dev/lib/python2.7/site-packages/tornado/gen.py”, line 1017, in run
yielded = self.gen.send(value)
File “/Users/claire/Documents/bokeh/bokeh/server/session.py”, line 42, in _needs_document_lock_wrapper
result = yield yield_for_all_futures(func(self, *args, **kwargs))
File “/Users/claire/Documents/bokeh/bokeh/server/session.py”, line 212, in _handle_patch
message.apply_to_document(self.document)
File “/Users/claire/Documents/bokeh/bokeh/server/protocol/messages/patch_doc.py”, line 85, in apply_to_document
doc.apply_json_patch(self.content)
File “/Users/claire/Documents/bokeh/bokeh/document.py”, line 862, in apply_json_patch
patched_obj.set_from_json(attr, value, models=references)
File “/Users/claire/Documents/bokeh/bokeh/core/properties.py”, line 733, in set_from_json
prop.set_from_json(self, json, models)
File “/Users/claire/Documents/bokeh/bokeh/core/properties.py”, line 371, in set_from_json
models)
File “/Users/claire/Documents/bokeh/bokeh/core/properties.py”, line 323, in set_from_json
return self.__set__(obj, json)
File “/Users/claire/Documents/bokeh/bokeh/core/properties.py”, line 456, in set
self._real_set(obj, old, value)
File “/Users/claire/Documents/bokeh/bokeh/core/properties.py”, line 446, in _real_set
self._trigger(obj, old, value, hint)
File “/Users/claire/Documents/bokeh/bokeh/core/properties.py”, line 397, in _trigger
obj.trigger(self.name, old, value, hint)
File “/Users/claire/Documents/bokeh/bokeh/model.py”, line 112, in trigger
super(Model, self).trigger(attr, old, new, hint)
File “/Users/claire/Documents/bokeh/bokeh/util/callback_manager.py”, line 105, in trigger
self._document._with_self_as_curdoc(invoke)
File “/Users/claire/Documents/bokeh/bokeh/document.py”, line 491, in _with_self_as_curdoc
return f()
File “/Users/claire/Documents/bokeh/bokeh/util/callback_manager.py”, line 102, in invoke
callback(attr, old, new)
File “/Users/claire/Documents/bokeh/bokeh/models/widgets/groups.py”, line 33, in
self.on_change('active', lambda attr, old, new: handler(new))
File “/Users/claire/Documents/test/plots_test.py”, line 19, in switch_plots
io.push()
File “/Users/claire/Documents/bokeh/bokeh/io.py”, line 465, in push
assert session_id is not None
AssertionError
···
On Thursday, March 3, 2016 at 9:04:06 AM UTC-8, Bryan Van de ven wrote:
Is this in a Bokeh App in the server, or are you using the bokeh.client API from a different python process?
Bryan
On Mar 1, 2016, at 4:35 PM, [email protected] wrote:
Hi, I’m trying to create an interactive visualization that uses the bokeh server through bokeh serve, but I’m having trouble updating the visualization. Specifically I want to update the visualization by changing the plots shown entirely (For example, changing from a single Figure to a GridPlot). I’ve found examples that show how to update plots by changing the data source, but I haven’t seen any examples that show how to add or remove plots. I’ve tried removing a previous layout from the document root and then adding a new layout, but am having trouble syncing this new state. Using bokeh.io.push() results in an error that the session_id doesn’t exist. I also noticed that the session_id printed to the console by the bokeh serve debugging is different from the session_id that is associated with bokeh.io._state. Is there a way to access the session of the bokeh application itself? And would this be the right way to go about syncing the display of components in an application?
Thanks,
Claire
–
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/764ca593-c68b-400d-a582-a7d37f90a721%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.