Pickling Bokeh plot

I am very new to Bokeh/Python but i am current working on a project where i created a django app, the user can upload data to the app and visualise it using bokeh. Is there anyway to save the plot to a database or file so that the user can open the plot even when the browser is closed It is called pickling if im not mistaken?

I am not sure this is a django question or bokeh question, I had googled about pickle, bokeh.document, curdoc and im very confused anyone mind explaining it to me?

Hi @seng_kit

Please see the bokeh documentation on exporting plots to see if it answers your questions or fits your general use case. If not, I’m sure others will be able to provide guidance on specific things you want to accomplish that might not be addressed therein. Here’s a link to the relevant section.https://docs.bokeh.org/en/latest/docs/user_guide/export.html

Pickling is capability of Python in general to serialize and deserialize data. It is used to convert Python objects so that it can be streamed over a network, saved to disk and reloaded, etc.

Based on your post, I’d think you would want to look at the graphics exporting rather than pickling or the other methods of serializing/de-serializing data.

Short answer: Bokeh does not support pickle. There are lots of reasons for this, among them a few:

  • Bokeh is actually two libraries, a Python and a JS one, and they have to communicate via a JSON protocol Given all the effort that necessarily went into a JSON serialization scheme, it did not make sense to put effort in to supporting pickle (which is no use for BokehJS) as well

  • Bokeh has been under highly active development for quite some time. Even if the user-facing API remains compatible, it would have been difficult/impossible to implement pickle support in a way that did not often break across releases

So as @_jm mentions, the export options are probably what you are looking for. But to be clear, those are for reconstituting pots directly as browser content, they won’t get you Python objects back. If you truly are looking to round-trip Python objects, there are potentially ways to do that, and we could discuss them, but be aware they would have version sensitivities (e.g. at present you might get forward-compat, but back-compat would break if the stored output has any newer Bokeh properties than the old version of Bokeh you try to re-hydrate things with). It would help if you could describe exactly what you are trying to accomplish at a conceptual/UX level in more detail.

Thanks for the answer Appreciate that

The idea is to allow user to upload a data file and visualise the data with bokeh. (They can select which columns they wish to visualise). next, the user can save the plot and proceed to create the next plot. After that they will have a list of plots they had saved before and they can create a dashboard with the plots.

Im targeting on time series data and my plots are fairly simple. (Without sliders… etc) But i do wish to keep some functions such as hovertools, zoom. Im worrying that the exporting method mentioned above will just display the plots as an image.

One more does this two totally not relevant to my problem?
https://docs.bokeh.org/en/latest/docs/reference/document.html
https://docs.bokeh.org/en/latest/docs/reference/io.html