from bokeh.embed import file_html
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import figure
from bokeh.resources import INLINE

source = ColumnDataSource(data=dict(x=[2, 3], y=[14, 20]))
plot = figure(height=260, sizing_mode="stretch_width",
              x_axis_label="Inspection", y_axis_label="Minutes")
plot.scatter("x", "y", source=source, size=16)
threshold = Slider(start=0, end=25, value=10, step=1,
                   title="Minimum minutes")
threshold.js_on_change("value", CustomJS(args=dict(source=source), code="""
const values = [8, 14, 20];
const x = [], y = [];
values.forEach((v, i) => {
  if (v >= cb_obj.value) { x.push(i + 1); y.push(v); }
});
source.data = {x, y};
source.change.emit();
"""))
page = file_html(column(threshold, plot), INLINE, "Inspection times")
with open("inspection.html", "w", encoding="utf-8") as f:
    f.write(page)
