Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combination of "export_png()" and "show()" causes error #8362

Closed
jnettels opened this issue Oct 25, 2018 · 2 comments
Closed

Combination of "export_png()" and "show()" causes error #8362

jnettels opened this issue Oct 25, 2018 · 2 comments

Comments

@jnettels
Copy link
Contributor

Hi there!
It pains me to bring up these export_png-related issues... but here I go again. This time it is an error that shows up when using export_png() and show() together:

In 0.13.0, the following works just fine:

from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.io import export_png, show, output_file

source = ColumnDataSource({'x': [2, 3, 4], 'y': [0.5, 1.5, 2.5]})
fig = figure(plot_width=1000, plot_height=300)
fig.hbar(y='y', right='x', height=0.4, source=source)

export_png(fig, filename="export fig.png")

doc_layout = layout([fig])

output_file('export_test.html', title='export test')
show(doc_layout)

...but in 1.0.0, it throws the following error for the line show(doc_layout):
RuntimeError: Models must be owned by only a single document, HelpTool(id='1026', ...) is already in a doc

Some observations:

  • I wonder if it has to do with the changes that allowed to fix export_png not exporting figures correctly #8020.
  • Not using either export_png or show works.
  • Using show(fig) instead of show(doc_layout) works, as well (but that is not really a workaround).
  • Using export_png after show works, too. This could be a workaround in most use cases, but is quite inconvenient in mine.

Many thanks for the 1.0 release, anyway. I read about it in the change log, and it really feels like the export function is now faster for multiple exports!

@bryevdv bryevdv added this to the 1.0.1 milestone Oct 25, 2018
@bryevdv
Copy link
Member

bryevdv commented Oct 28, 2018

This diff fixes:

diff --git a/bokeh/embed/util.py b/bokeh/embed/util.py
index 36333a39c..e0c610f03 100644
--- a/bokeh/embed/util.py
+++ b/bokeh/embed/util.py
@@ -113,7 +113,7 @@ def OutputDocumentFor(objs, apply_theme=None, always_new=False):

     def finish(): pass

-    docs = set(x.document for x in objs)
+    docs = _compute_current_docs(objs)

     # handle a single shared document, or missing document
     if len(docs) == 1:
@@ -317,6 +317,14 @@ be used. For more information on building and running Bokeh applications, see:
     http://bokeh.pydata.org/en/latest/docs/user_guide/server.html
 """

+def _compute_current_docs(objs):
+    docs = set()
+    for obj in objs:
+        docs.add(obj.document)
+        for ref in obj.references():
+            docs.add(ref.document)
+    return docs
+
 def _create_temp_doc(models):
     doc = Document()
     for m in models:

I will submit a PR once I have time to figure out some tests.

@bryevdv
Copy link
Member

bryevdv commented Oct 31, 2018

closed by #8386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants