def render_mimebundle(model, doc, comm): """ Displays bokeh output inside a notebook using the PyViz display and comms machinery. """ if not isinstance(model, LayoutDOM): raise ValueError('Can only render bokeh LayoutDOM models') add_to_doc(model, doc, True) target = model.ref['id'] # Publish plot HTML bokeh_script, bokeh_div, _ = bokeh.embed.notebook.notebook_content( model, comm.id) html = encode_utf8(bokeh_div) # Publish bokeh plot JS msg_handler = bokeh_msg_handler.format(plot_id=target) comm_js = comm.js_template.format(plot_id=target, comm_id=comm.id, msg_handler=msg_handler) bokeh_js = '\n'.join([comm_js, bokeh_script]) bokeh_js = embed_js.format(widget_id=target, plot_id=target, html=html) + bokeh_js data = { EXEC_MIME: '', 'text/html': html, 'application/javascript': bokeh_js } metadata = {EXEC_MIME: {'id': target}} return data, metadata
def notebook_show(obj, doc, comm): """ Displays bokeh output inside a notebook. """ target = obj.ref['id'] load_mime = 'application/vnd.holoviews_load.v0+json' exec_mime = 'application/vnd.holoviews_exec.v0+json' # Publish plot HTML bokeh_script, bokeh_div, _ = bokeh.embed.notebook.notebook_content(obj, comm.id) publish_display_data(data={'text/html': encode_utf8(bokeh_div)}) # Publish comm manager JS = '\n'.join([PYVIZ_PROXY, JupyterCommManager.js_manager]) publish_display_data(data={load_mime: JS, 'application/javascript': JS}) # Publish bokeh plot JS msg_handler = bokeh_msg_handler.format(plot_id=target) comm_js = comm.js_template.format(plot_id=target, comm_id=comm.id, msg_handler=msg_handler) bokeh_js = '\n'.join([comm_js, bokeh_script]) # Note: extension should be altered so text/html is not required publish_display_data(data={exec_mime: '', 'text/html': '', 'application/javascript': bokeh_js}, metadata={exec_mime: {'id': target}})
def render_model(model, comm=None): if not isinstance(model, Model): raise ValueError("notebook_content expects a single Model instance") target = model.ref['id'] (docs_json, [render_item]) = standalone_docs_json_and_render_items([model]) div = div_for_render_item(render_item) render_item = render_item.to_json() script = DOC_NB_JS.render( docs_json=serialize_json(docs_json), render_items=serialize_json([render_item]), ) bokeh_script, bokeh_div = encode_utf8(script), encode_utf8(div) html = "<div id='{id}'>{html}</div>".format(id=target, html=bokeh_div) # Publish bokeh plot JS msg_handler = bokeh_msg_handler.format(plot_id=target) if comm: comm_js = comm.js_template.format(plot_id=target, comm_id=comm.id, msg_handler=msg_handler) bokeh_js = '\n'.join([comm_js, bokeh_script]) else: bokeh_js = bokeh_script bokeh_js = embed_js.format( widget_id=target, plot_id=target, html=bokeh_div) + bokeh_js data = { EXEC_MIME: '', 'text/html': html, 'application/javascript': bokeh_js } metadata = {EXEC_MIME: {'id': target}} return data, metadata