Exporting interactive bokeh plots from one file to another

Just a general question, I’m wondering whether it is possible to export a bokeh plot built in one notebook file into another file that will be used for dashboard layouts/styling using another framework like panel or something. Ideally still preserving the interactive elements of the original plot. I noticed in the documentation that you seem to be able to do this for building web apps incl bokeh but in this case I just want it to run on a local server using panel.

Thank you

For sample reference plot I’m referring to, something like the one here would be very similar to what I’m trying to export

Did you have a look here:

What have you tried, what did not work (ideally with minimal reproducible example)?

I’ve tried doing below to the file where my plot was created

html = file_html(layout, CDN)
file_path = "<HTML FILE PATH>"
with open(file_path, "w", encoding="utf-8") as file:
    file.write(html)

Followed by these snippets which will be executed in the document for layouts etc

from bokeh.layouts import column
from bokeh.models.widgets import Div
from bokeh.io import curdoc
from bokeh.plotting import figure, output_file, show

with open("<HTML FILE PATH>", "r") as html_file:
    html_content = html_file.read()

embedded_html_div = Div(text=html_content)

layout = column(embedded_html_div)

curdoc().add_root(layout)

However, I’m still struggling to incorporate the plot (i.e view it modify it, use it in a variable etc) into the new document as I’m unsure how to proceed from the embedded_html_div pt to actually getting the plot as it was in the original document. I’ve also tried bokeh serve operations but that just outputs a blank page, even though the actual plot is displayed fine when I open the html document obtained from the first block of snippets

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