
Hi there,
just started to work with Bokeh to generate a simple server that allows users on an offine workstation, to load .txt files from a metrology tool to generate plots.
The files can have a variable amount of sections, so I want to generate variable number of plots depending on file content.
I found this question about dynamically adding plots and ported it to the most recent Bokeh version, but it seems I cannot create a reference to the Bokeh.Plotting definitions:
Sample Code:
# myapp.py
from bokeh.layouts import column
from bokeh.models import Button, CustomJS
from bokeh.plotting import figure, curdoc
f1 = figure()# add a line renderer and legend to the plot
f1.line(x=[1,2,3], y=[3,2,3], legend_label="Temp.")
main_row = column(f1)
button2=Button(label='Add plot')
button2.js_on_event('button_click', CustomJS(args=dict(main_row=main_row), code="""
const bok = Bokeh; //works
const plt = Bokeh.Plotting; //does not work
var f = plt.Figure();
f.line({x: [1, 2, 3], y: [3, 2, 1]});
main_row.children.push(f);
main_row.properties.children.change.emit();
"""))
curdoc().add_root(column(button2,main_row))
In the browser’s debugger I get the Error Cannot read properties of undefined (reading 'Figure') because plt is indeed undefined. In the Debugging tools of the browser, bok does not have a Plotting module.
Assume it has something to do with the separate Bokeh-api.js - but I could not figure out, how to integrate that - help is appreciated…


