Embed Bokeh Curdoc

Is it possible to embed bokeh curdoc. I am using curdoc().add_root(self.layout) to show my class of guitar fretboard. In curdoc, it has buttons as well as plots.

I tried doing:
html = file_html(curdoc(), CDN, “my plot”)

Thank you

also for this i got. html = file_html(self.layout, CDN, “my plot”)

You are generating standalone HTML/JS output, but trying to use real Python
callbacks (i.e. with on_change or on_event). This combination cannot work.

Only JavaScript callbacks may be used with standalone output. For more
information on JavaScript callbacks with Bokeh, see:


Alternatively, to use real Python callbacks, a Bokeh server application may
be used. For more information on building and running Bokeh applications, see:


@anoSF The message tries to be clear. Things like on_change callbacks can only function with a Bokeh server app, because the Bokeh server is the the Python process that runs the callback code. file_html only generates standalone, static HTML that is not connected to any Python process, so on_change callbacks cannot function.

It’s not really clear what your actual situation or goal here is, so it is hard to advise further. First things first: are you running a Bokeh server? If so are you asking how to embed that in other pages? If that is the case, then there are special APIs just for embedding Bokeh server apps:


If that’s not the case then you’ll need to explain the overall setup and situation in more detail.

yes i am running a server. I do bokeh serve --show fileName.py and it will call curdoc().add_root(self.layout). I want to be able to embed that into another webpage, maybe using HTML or some kind of framework. I want it to be able to manipulate the data.

I did use server_document() and got the following and just directly copy and paste into my HTML page but it doesn’t appear.

script id="p1753">
    (function() {
      const xhr = new XMLHttpRequest()
      xhr.responseType = 'blob';
      xhr.open('GET', "http://localhost:5006/autoload.js?bokeh-autoload-element=p1753&bokeh-absolute-url=http://localhost:5006", true);
      xhr.onload = function (event) {
        const script = document.createElement('script');
        const src = URL.createObjectURL(event.target.response);
        script.src = src;

Are there any messages in the browser’s JS console? That is where errors on the JS side of things will show up.

And what about the Bokeh server console log? I expect there is a corresponding error about disallowing the webscocket connection. In which case you need to set --allow-websocket-origin to tell Bokeh what origins are allowed (the error message has actionable details).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.