Goal: I’m trying to close a server when the browser tab is closed or when the user clicks on some sort of “Quit” button.
Longer Description: In the case where I create a stand-alone bokeh server I am able to create a “Quit” Button which will io_loop.stop() in its callback but that leaves the client-side plot window intact. I assume that window.close() in a CustomJS callback won’t work (because the window was not created by the page’s javascript) and furthermore I don’t know how to generate a combination of javascript and Python in response to a user generated event.
The best solution, as far as I can tell (and I know nothing of the various hooks that might be available) would be to add a callback to onbeforeunload which triggers some server-side callback equivalent to that of a my aforementioned “Quit” button. But (1) I don’t know how to inject “global” javascript code to a plot (not associated with a specific callback) and (2) I don’t know how to use the websocket/REST API to trigger a specific callback (I suppose I can call the click() method on an invisible button, but that worries me since it would be happening during the unload so the event might never be triggered)…
Manor.

