plot = generate_plot()
# Apply zoom-level
plot.x_range = Range1d(….) # skip line 1
plot.y_range = Range1d(….) # skip line 2
div_id = "".join(choices(ascii_letters, k=16)) # skip line 3
fig_dict = json_item(plot, div_id) # skip line 4
json_figure = json.dumps(fig_dict) # skip line 5
Can anyone provide suggestions on how to achieve this? Alternatively, is there a possibility to apply plot.x_range and plot.y_range on an embedded bokeh plot?
Yes, you need to fech the chart data/config from your backend.
On the other hand, if you want to handle bokeh directly with JS you should consider the option of passing only the data of the graph from the backend (x,y) and then with that data generate directly the graph with bokehjs, having the control in the JS.
Definitely need some additional context here. Bokeh plots are zoomable purely on the JS side by default using standard wheel and box zoom tools, etc., assuming you just want to zoom one set of data. Do you mean that you have multi-resolution data and some other mechanism for specifying “zoom level” (a streamlit… widget? control of some sort? I am not very familiar with streamlit at all) and want to be able to switch between different levels of the data based on that? If so can you just add all the data to one plot up front and selectively turn off and on the visibility of the glyphs for each data set? That seems much simpler, but I am also not sure I understand the situation.
Sorry for the late reply. The problem is that after converting/serializing the plot to an embeddable JSON/ Object, I cannot revert it back to the plot again so I cannot set properties like x_range, and y_range.
The Bokeh server will keep the Python <–> JS sides in sync. There are APIs for converting Python Bokeh documents into JSON to be re-constituted as JS objects. There are not currently any official APIs for the reverse (i.e. for converting JSON into Python objects)