Bokeh: STAMEN_TONER map breaks after refreshing browser page.

Created on 8 Jul 2016  路  3Comments  路  Source: bokeh/bokeh

The STAMEN_TONER map stops working when I do the following (using version 0.12.0):

  • Run a Bokeh server with bokeh serve tile_bug.py
  • Navigate to localhost:5006/tile_bug in web browser.
  • Hit the refresh button in the browser.

This spits out the following error message:

Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7f3df75644d0>: Models must be owned by only a single document, <bokeh.models.tiles.WMTSTileSource object at 0x7f3df76956d0> is already in a doc
File "model.py", line 91, in _attach_document:
raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self)) Traceback (most recent call last):
  File "/home/tanner/anaconda2/lib/python2.7/site-packages/bokeh/application/handlers/code_runner.py", line 83, in run
    exec(self._code, module.__dict__)
  File "/home/tanner/Work/DevTeam/numerical_computing/Labs/Vol3A/Bokeh/tile_bug.py", line 11, in <module>
    curdoc().add_root(fig)
  File "/home/tanner/anaconda2/lib/python2.7/site-packages/bokeh/document.py", line 412, in add_root
    self._pop_all_models_freeze()
  File "/home/tanner/anaconda2/lib/python2.7/site-packages/bokeh/document.py", line 317, in _pop_all_models_freeze
    self._recompute_all_models()
  File "/home/tanner/anaconda2/lib/python2.7/site-packages/bokeh/document.py", line 341, in _recompute_all_models
    a._attach_document(self)
  File "/home/tanner/anaconda2/lib/python2.7/site-packages/bokeh/model.py", line 91, in _attach_document
    raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self))
RuntimeError: Models must be owned by only a single document, <bokeh.models.tiles.WMTSTileSource object at 0x7f3df76956d0> is already in a doc

Here is my tile_bug.py code:

from bokeh.io import curdoc
from bokeh.plotting import Figure
from bokeh.tile_providers import STAMEN_TONER

fig = Figure(plot_width=1100, plot_height=650, tools=["wheel_zoom", "pan"],
            x_range=(-13000000, -7000000), y_range=(2750000, 6250000), webgl=True,
            active_scroll="wheel_zoom")
fig.axis.visible = False
fig.add_tile(STAMEN_TONER)

curdoc().add_root(fig)
duplicate

Most helpful comment

Oh, sure enough, STAMEN_TONER is a single actual model object and using it this way in a server app reuses it across documents in a way that cannot be supported for model objects.

The good news is, you can just create your own objects in your script, the same way bokeh.tile_providers does:

STAMEN_TONER = WMTSTileSource(
    url='http://tile.stamen.com/toner/{Z}/{X}/{Y}.png',
    attribution=(
        'Map tiles by <a href="http://stamen.com">Stamen Design</a>, '
        'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.'
        'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, '
        'under <a href="http://www.openstreetmap.org/copyright">ODbL</a>'
    )
)

Put that in your script instead of the import and you will get a new model for every session.

ping @brendancol

All 3 comments

Oh, sure enough, STAMEN_TONER is a single actual model object and using it this way in a server app reuses it across documents in a way that cannot be supported for model objects.

The good news is, you can just create your own objects in your script, the same way bokeh.tile_providers does:

STAMEN_TONER = WMTSTileSource(
    url='http://tile.stamen.com/toner/{Z}/{X}/{Y}.png',
    attribution=(
        'Map tiles by <a href="http://stamen.com">Stamen Design</a>, '
        'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.'
        'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, '
        'under <a href="http://www.openstreetmap.org/copyright">ODbL</a>'
    )
)

Put that in your script instead of the import and you will get a new model for every session.

ping @brendancol

Thanks for the workaround

dupe of #6590, closing this and keeping the other issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thoth291 picture thoth291  路  4Comments

agoodm picture agoodm  路  4Comments

abdelwahed picture abdelwahed  路  4Comments

jnettels picture jnettels  路  3Comments

darribas picture darribas  路  3Comments