I am trying to defer generation of some plots in BokehJS without any python backend. Json_item is exactly what I need but it doesn’t seem to be in the javascript “embed” object. Does this exists? Is it hiding somewhere?
Thanks
I am trying to defer generation of some plots in BokehJS without any python backend. Json_item is exactly what I need but it doesn’t seem to be in the javascript “embed” object. Does this exists? Is it hiding somewhere?
Thanks
@eribean There’s not a json_item
on the BokehJS side at present, maybe there should be. But I think you can just construct the object that embed_item
expects. Something like (untested):
const doc_json = doc.to_json()
item = {
doc: doc_json,
root_id: doc_json.roots.root_ids[0]
}
embed_item(doc_json, "div_id")
Thanks @Bryan, worked like a charm! Weirdly enough the rendering is consistently faster so double win!
Just an FYI, if I use
Bokeh.Plotting.show(somePlot, location)
then location expects a selector
'#div_id'
However, embed_item
expects an id per your response
'div_id'
Hello! I am trying to achieve a similar result but I find the answer a bit confusing and inconclusive, can you help clarify? I am on Bokeh 2.4.3 Firstly, shouldn’t the solution be:
# Python side
const doc_json = doc.to_json(include_defaults=True)
item = {
doc: doc_json,
root_id: doc_json.roots.root_ids[0]
}
// JavaScript side
embed_item(doc_json, "div_id")
instead of the posted answer below:
const doc_json = doc.to_json()
item = {
doc: doc_json,
root_id: doc_json.roots.root_ids[0]
}
embed_item(doc_json, "div_id")
@Festus_Yeboah On the Python side just use json_item
as described in the docs. There is generally no need to use the low-level to_json
API in Python. This question was about accomplishing something using only JS (where json_item
does not exist).
Hi Bryan, Thanks for your quick reply. I ended up creating a new topic with more clarifications on what I want to achieve.
https://discourse.bokeh.org/t/passing-generated-plot-in-python-to-javascript/10080