Repository: bokeh/bokeh

Issue:
components not working with notebook show in the same cell
#### ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

`bokeh`: 0.12.11
`python`: 3.6
OS: macOS
Browser: Safari

#### Description of expected behavior and the observed behavior

When using components with stacked vbar or hbar, an error is thrown. In the notebook environment, I have no issues displaying the figure.

#### Complete, minimal, self-contained example code that reproduces the issue

```
# code goes here between backticks
from bokeh.plotting import figure
from bokeh.io import output_notebook, show
from bokeh.embed import components
from bokeh.models import ColumnDataSource

output_notebook()

data = {'class': ['a', 'b'],
        '2015': [1, 2],
        '2016': [2, 3],
        '2017': [3, 5]}

source = ColumnDataSource(data)

years = ['2015', '2016', '2017']
p = figure(y_range=data['class'])
p.hbar_stack(stackers=years, y='class', source=source, height=0.5, color=['red', 'blue', 'green'])
components(p)
```

#### Stack traceback and/or browser JavaScript console output

```
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/embed/standalone.py in _add_doc_to_models(doc, models)
    322                 try:
--> 323                     doc.add_root(model)
    324                     models_to_dedoc.append(model)

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/document/document.py in add_root(self, model, setter)
    242         finally:
--> 243             self._pop_all_models_freeze()
    244         self._trigger_on_change(RootAddedEvent(self, model, setter))

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/document/document.py in _pop_all_models_freeze(self)
    922         if self._all_models_freeze_count == 0:
--> 923             self._recompute_all_models()
    924 

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/document/document.py in _recompute_all_models(self)
    945         for a in to_attach:
--> 946             a._attach_document(self)
    947         self._all_models = recomputed

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/model.py in _attach_document(self, doc)
    552         if self._document is not None and self._document is not doc:
--> 553             raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self))
    554         doc.theme.apply_to_model(self)

RuntimeError: Models must be owned by only a single document, ColumnDataSource(id='d7459854-95b5-4527-9108-e85dc7ee6693', ...) is already in a doc

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-23-9ba2b2821a0e> in <module>()
      2 p = figure(y_range=data['class'])
      3 p.hbar_stack(stackers=years, y='class', source=source, height=0.5, color=['red', 'blue', 'green'])
----> 4 components(p)

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/util/api.py in wrapper(*args, **kw)
    188         @wraps(obj)
    189         def wrapper(*args, **kw):
--> 190             return obj(*args, **kw)
    191 
    192         wrapper.__bkversion__ = version

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/embed/standalone.py in components(models, wrap_script, wrap_plot_info, theme)
    209 
    210     # 2) Append models to one document. Either pre-existing or new and render
--> 211     with _ModelInDocument(models, apply_theme=theme):
    212         (docs_json, render_items) = standalone_docs_json_and_render_items(models)
    213 

~/anaconda/envs/my_env/lib/python3.6/contextlib.py in __enter__(self)
     79     def __enter__(self):
     80         try:
---> 81             return next(self.gen)
     82         except StopIteration:
     83             raise RuntimeError("generator didn't yield") from None

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/embed/standalone.py in _ModelInDocument(models, apply_theme)
    304         doc.theme = apply_theme
    305 
--> 306     models_to_dedoc = _add_doc_to_models(doc, models)
    307 
    308     if settings.perform_document_validation():

~/anaconda/envs/my_env/lib/python3.6/site-packages/bokeh/embed/standalone.py in _add_doc_to_models(doc, models)
    329                            'single document). This may indicate a usage '
    330                            'error.'.format(child, model))
--> 331                     raise RuntimeError(msg)
    332     return models_to_dedoc
    333 

RuntimeError: Sub-model (id='d7459854-95b5-4527-9108-e85dc7ee6693', ...) of the root model Figure(id='464f72aa-dbc1-4bc1-8fab-98089aed6744', ...) is already owned by another document (Models must be owned by only a single document). This may indicate a usage error.
```
#### Screenshots or screencasts of the bug in action

No screenshots necessary.


Discussion:

Resolving patch:
diff --git a/bokeh/embed/standalone.py b/bokeh/embed/standalone.py
--- a/bokeh/embed/standalone.py
+++ b/bokeh/embed/standalone.py
@@ -130,6 +130,9 @@ def components(models, wrap_script=True, wrap_plot_info=True, theme=FromCurdoc):
         <script src="http://cdn.pydata.org/bokeh/release/bokeh-widgets-x.y.z.min.js"></script>
         <script src="http://cdn.pydata.org/bokeh/release/bokeh-tables-x.y.z.min.js"></script>
 
+    Note that in Jupyter Notebooks, it is not possible to use components and show in
+    the same notebook cell.
+
     Args:
         models (Model|list|dict|tuple) :
             A single Model, a list/tuple of Models, or a dictionary of keys and Models.


Test patch: