Pickle Bokeh Plotting Objects

Does anyone have any experience with pickling bokeh plot objects, saving them to a file or database , retrieving them and perhaps using them again to update the data sources or integrate the object with a bokeh server?

I would be grateful for some advice or resources on how to perform these actions.

I generate a lot of plot objects from reports and would like to save them when working with my web application. Any ideas?

Thank you

Hi,

Bokeh already has specialized serialization requirements, in order to communicate between Python Bokeh and BokehJS. I would encourage you to use the existing JSON representation that Bokeh itself generates, and not try to use pickle. I have very little confidence that pickle would currently work, or that it could easily be made to work.

The Documents class has methods to generate and load JSON:

  bokeh.document — Bokeh 3.3.2 Documentation
  bokeh.document — Bokeh 3.3.2 Documentation

You should be able to use these to save or replace curdoc()

Thanks,

Bryan

···

On Jun 16, 2017, at 11:45, RiskiBizniz <[email protected]> wrote:

Does anyone have any experience with pickling bokeh plot objects, saving them to a file or database , retrieving them and perhaps using them again to update the data sources or integrate the object with a bokeh server?

I would be grateful for some advice or resources on how to perform these actions.

I generate a lot of plot objects from reports and would like to save them when working with my web application. Any ideas?

Thank you

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/374561d1-74f1-4759-a46b-5de61c1e272e%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

I was trying this with bokeh 0.12.5 using the example from “bokeh/examples/plotting/file/legend.py” with no success.

from bokeh.document import Document
from bokeh.plotting import show, output_file, figure
from bokeh.layouts import gridplot
import numpy as np

output_file(‘test3.html’)

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)

TOOLS = “pan,wheel_zoom,box_zoom,reset,save,box_select”

p1 = figure(title=“Legend Example”, tools=TOOLS)

p1.circle(x, y, legend=“sin(x)”)
p1.circle(x, 2y, legend="2sin(x)“, color=“orange”)
p1.circle(x, 3y, legend="3sin(x)”, color=“green”)

p2 = figure(title=“Another Legend Example”, tools=TOOLS)

p2.circle(x, y, legend=“sin(x)”)
p2.line(x, y, legend=“sin(x)”)

p2.line(x, 2y, legend="2sin(x)", line_dash=(4, 4), line_color=“orange”, line_width=2)

p2.square(x, 3y, legend="3sin(x)“, fill_color=None, line_color=“green”)
p2.line(x, 3y, legend="3sin(x)”, line_color=“green”)

output = gridplot(p1, p2, ncols=2, plot_width=400, plot_height=400)

doc = Document()
doc.add_root(output)
t = doc.to_json()

del doc

newdoc = Document()
newdoc.from_json(t)
show(newdoc)

``

I get an

AttributeError: ‘Document’ object has no attribute ‘references’

``

Would you be able to point me to an example of how to implement this functionality?

···

On Friday, June 16, 2017 at 12:55:54 PM UTC-4, Bryan Van de ven wrote:

Hi,

Bokeh already has specialized serialization requirements, in order to communicate between Python Bokeh and BokehJS. I would encourage you to use the existing JSON representation that Bokeh itself generates, and not try to use pickle. I have very little confidence that pickle would currently work, or that it could easily be made to work.

The Documents class has methods to generate and load JSON:

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json)

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json)

You should be able to use these to save or replace curdoc()

Thanks,

Bryan

On Jun 16, 2017, at 11:45, RiskiBizniz [email protected] wrote:

Does anyone have any experience with pickling bokeh plot objects, saving them to a file or database , retrieving them and perhaps using them again to update the data sources or integrate the object with a bokeh server?

I would be grateful for some advice or resources on how to perform these actions.

I generate a lot of plot objects from reports and would like to save them when working with my web application. Any ideas?

Thank you


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/374561d1-74f1-4759-a46b-5de61c1e272e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

This seems like a bug (or at least a missing feature). Old document references should be discarded when “re-constituting” JSON (or at least there should be an option for that). Please file a GitHub issue with all this information:

Thanks,

Bryan

···

On Friday, June 16, 2017 at 2:14:38 PM UTC-5, RiskiBizniz wrote:

Hi Bryan,

I was trying this with bokeh 0.12.5 using the example from “bokeh/examples/plotting/file/legend.py” with no success.

from bokeh.document import Document
from bokeh.plotting import show, output_file, figure
from bokeh.layouts import gridplot
import numpy as np

output_file(‘test3.html’)

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)

TOOLS = “pan,wheel_zoom,box_zoom,reset,save,box_select”

p1 = figure(title=“Legend Example”, tools=TOOLS)

p1.circle(x, y, legend=“sin(x)”)
p1.circle(x, 2y, legend="2sin(x)“, color=“orange”)
p1.circle(x, 3y, legend="3sin(x)”, color=“green”)

p2 = figure(title=“Another Legend Example”, tools=TOOLS)

p2.circle(x, y, legend=“sin(x)”)
p2.line(x, y, legend=“sin(x)”)

p2.line(x, 2y, legend="2sin(x)", line_dash=(4, 4), line_color=“orange”, line_width=2)

p2.square(x, 3y, legend="3sin(x)“, fill_color=None, line_color=“green”)
p2.line(x, 3y, legend="3sin(x)”, line_color=“green”)

output = gridplot(p1, p2, ncols=2, plot_width=400, plot_height=400)

doc = Document()
doc.add_root(output)
t = doc.to_json()

del doc

newdoc = Document()
newdoc.from_json(t)
show(newdoc)

``

I get an

AttributeError: ‘Document’ object has no attribute ‘references’

``

Would you be able to point me to an example of how to implement this functionality?

On Friday, June 16, 2017 at 12:55:54 PM UTC-4, Bryan Van de ven wrote:

Hi,

Bokeh already has specialized serialization requirements, in order to communicate between Python Bokeh and BokehJS. I would encourage you to use the existing JSON representation that Bokeh itself generates, and not try to use pickle. I have very little confidence that pickle would currently work, or that it could easily be made to work.

The Documents class has methods to generate and load JSON:

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json)

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json)

You should be able to use these to save or replace curdoc()

Thanks,

Bryan

On Jun 16, 2017, at 11:45, RiskiBizniz [email protected] wrote:

Does anyone have any experience with pickling bokeh plot objects, saving them to a file or database , retrieving them and perhaps using them again to update the data sources or integrate the object with a bokeh server?

I would be grateful for some advice or resources on how to perform these actions.

I generate a lot of plot objects from reports and would like to save them when working with my web application. Any ideas?

Thank you


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/374561d1-74f1-4759-a46b-5de61c1e272e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

FYI someone else already made an issue (unless it was you):

···

On Tuesday, June 20, 2017 at 10:16:39 AM UTC-5, Bryan Van de ven wrote:

Hi,

This seems like a bug (or at least a missing feature). Old document references should be discarded when “re-constituting” JSON (or at least there should be an option for that). Please file a GitHub issue with all this information:

https://github.com/bokeh/bokeh/issues

Thanks,

Bryan

On Friday, June 16, 2017 at 2:14:38 PM UTC-5, RiskiBizniz wrote:

Hi Bryan,

I was trying this with bokeh 0.12.5 using the example from “bokeh/examples/plotting/file/legend.py” with no success.

from bokeh.document import Document
from bokeh.plotting import show, output_file, figure
from bokeh.layouts import gridplot
import numpy as np

output_file(‘test3.html’)

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)

TOOLS = “pan,wheel_zoom,box_zoom,reset,save,box_select”

p1 = figure(title=“Legend Example”, tools=TOOLS)

p1.circle(x, y, legend=“sin(x)”)
p1.circle(x, 2y, legend="2sin(x)“, color=“orange”)
p1.circle(x, 3y, legend="3sin(x)”, color=“green”)

p2 = figure(title=“Another Legend Example”, tools=TOOLS)

p2.circle(x, y, legend=“sin(x)”)
p2.line(x, y, legend=“sin(x)”)

p2.line(x, 2y, legend="2sin(x)", line_dash=(4, 4), line_color=“orange”, line_width=2)

p2.square(x, 3y, legend="3sin(x)“, fill_color=None, line_color=“green”)
p2.line(x, 3y, legend="3sin(x)”, line_color=“green”)

output = gridplot(p1, p2, ncols=2, plot_width=400, plot_height=400)

doc = Document()
doc.add_root(output)
t = doc.to_json()

del doc

newdoc = Document()
newdoc.from_json(t)
show(newdoc)

``

I get an

AttributeError: ‘Document’ object has no attribute ‘references’

``

Would you be able to point me to an example of how to implement this functionality?

On Friday, June 16, 2017 at 12:55:54 PM UTC-4, Bryan Van de ven wrote:

Hi,

Bokeh already has specialized serialization requirements, in order to communicate between Python Bokeh and BokehJS. I would encourage you to use the existing JSON representation that Bokeh itself generates, and not try to use pickle. I have very little confidence that pickle would currently work, or that it could easily be made to work.

The Documents class has methods to generate and load JSON:

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json)

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json)

You should be able to use these to save or replace curdoc()

Thanks,

Bryan

On Jun 16, 2017, at 11:45, RiskiBizniz [email protected] wrote:

Does anyone have any experience with pickling bokeh plot objects, saving them to a file or database , retrieving them and perhaps using them again to update the data sources or integrate the object with a bokeh server?

I would be grateful for some advice or resources on how to perform these actions.

I generate a lot of plot objects from reports and would like to save them when working with my web application. Any ideas?

Thank you


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/374561d1-74f1-4759-a46b-5de61c1e272e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sorry here is the link:

···

On Wednesday, June 21, 2017 at 8:34:17 AM UTC-5, Bryan Van de ven wrote:

FYI someone else already made an issue (unless it was you):

On Tuesday, June 20, 2017 at 10:16:39 AM UTC-5, Bryan Van de ven wrote:

Hi,

This seems like a bug (or at least a missing feature). Old document references should be discarded when “re-constituting” JSON (or at least there should be an option for that). Please file a GitHub issue with all this information:

https://github.com/bokeh/bokeh/issues

Thanks,

Bryan

On Friday, June 16, 2017 at 2:14:38 PM UTC-5, RiskiBizniz wrote:

Hi Bryan,

I was trying this with bokeh 0.12.5 using the example from “bokeh/examples/plotting/file/legend.py” with no success.

from bokeh.document import Document
from bokeh.plotting import show, output_file, figure
from bokeh.layouts import gridplot
import numpy as np

output_file(‘test3.html’)

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)

TOOLS = “pan,wheel_zoom,box_zoom,reset,save,box_select”

p1 = figure(title=“Legend Example”, tools=TOOLS)

p1.circle(x, y, legend=“sin(x)”)
p1.circle(x, 2y, legend="2sin(x)“, color=“orange”)
p1.circle(x, 3y, legend="3sin(x)”, color=“green”)

p2 = figure(title=“Another Legend Example”, tools=TOOLS)

p2.circle(x, y, legend=“sin(x)”)
p2.line(x, y, legend=“sin(x)”)

p2.line(x, 2y, legend="2sin(x)", line_dash=(4, 4), line_color=“orange”, line_width=2)

p2.square(x, 3y, legend="3sin(x)“, fill_color=None, line_color=“green”)
p2.line(x, 3y, legend="3sin(x)”, line_color=“green”)

output = gridplot(p1, p2, ncols=2, plot_width=400, plot_height=400)

doc = Document()
doc.add_root(output)
t = doc.to_json()

del doc

newdoc = Document()
newdoc.from_json(t)
show(newdoc)

``

I get an

AttributeError: ‘Document’ object has no attribute ‘references’

``

Would you be able to point me to an example of how to implement this functionality?

On Friday, June 16, 2017 at 12:55:54 PM UTC-4, Bryan Van de ven wrote:

Hi,

Bokeh already has specialized serialization requirements, in order to communicate between Python Bokeh and BokehJS. I would encourage you to use the existing JSON representation that Bokeh itself generates, and not try to use pickle. I have very little confidence that pickle would currently work, or that it could easily be made to work.

The Documents class has methods to generate and load JSON:

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.to_json)

    [http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json](http://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.Document.from_json)

You should be able to use these to save or replace curdoc()

Thanks,

Bryan

On Jun 16, 2017, at 11:45, RiskiBizniz [email protected] wrote:

Does anyone have any experience with pickling bokeh plot objects, saving them to a file or database , retrieving them and perhaps using them again to update the data sources or integrate the object with a bokeh server?

I would be grateful for some advice or resources on how to perform these actions.

I generate a lot of plot objects from reports and would like to save them when working with my web application. Any ideas?

Thank you


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/374561d1-74f1-4759-a46b-5de61c1e272e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.