
Hello, I have a Bokeh plot created in Python/ Streamlit and embedded in a React application. I want to improve performance by keeping the zoom level on the client side so that Streamlit does not refresh. To achieve this, I plan to partially generate the plot in Python and then pass it down to JavaScript. After that, I want to add the zoom levels in JavaScript before embedding the plot.
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
# json_figure is sent to javascript to be embedded using the example in the bokeh documentation for version 2.4.3
What I want to do is to skip the block of code above to be able to send the plot down to the javascript script and apply zoom on the javascript side then generate the json_figure and embed it. The problem is plot is not JSON serializable and plot.to_json() did not work.
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?
I thought the example here Json_item for javascript is helpful but doesn’t address my issue completely.
Thank you.



