Stop Server with a button

Hi everyone !

I’m trying to stop the localHost with a “Stop” button on my interface, however I can’t find the function to stop the “Curdoc”, could you help me please?

from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.models import Button, CustomJS, Div
from bokeh.layouts import column
from bokeh import events

div = Div(width=400)
button = Button(label=“STOP”, width=300)

p = figure(plot_width=400, plot_height=400)

p.square([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=[10, 15, 20, 25, 30], color=“firebrick”, alpha=0.6)

button.js_on_event(events.ButtonClick, CustomJS(args=dict(div=div), code="""
div.text = “Stop server”;
“”"))
doc=curdoc()
doc.add_root(column(p,button))

Best Regards,
Pierre-yves

from tornado.ioloop import IOLoop

from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import Button
from bokeh.plotting import figure


def stop_server():
    IOLoop.current().stop()


p = figure()
p.circle(0, 0)

button = Button(label="STOP")
button.on_click(stop_server)
curdoc().add_root(column(p, button))
2 Likes

Thank you, for fast answer ! :slight_smile: And for the solution my lord :slight_smile: