We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Incomplete docs re embedding when using data tables
Hi, I banged my head a bit trying to use `components` to render tables and failing while `file_html` would work well.
Turns out we now need to include: 
```html
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.9.min.css" type="text/css" />
<script type="text/javascript" src="https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.9.min.js"></script>
```
in order for data tables to render properly and this is not mentioned in the embed sections of the User Guide or the Reference.

Having a look right now how the docs are built to see if I can provide help with a PR if that's not fixed already.

EDIT: Going through the docs to prepare a PR, I read in the 0.12.7 release notes that the change should be transparent as Bokeh would load the `-tables` resources automatically when necessary. It wasn't the case for me. But maybe it wasn't meant for the `components` use case?

I will provide a PR later today. Just waiting for a feedback on that last question to see whether this paragraph in the 0.12.7 release notes should be reworded if `components` is not covered by the automatic process.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bokeh/embed/standalone.py`
Content:
```
1 #-----------------------------------------------------------------------------
2 # Copyright (c) 2012 - 2017, Anaconda, Inc. All rights reserved.
3 #
4 # Powered by the Bokeh Development Team.
5 #
6 # The full license is in the file LICENSE.txt, distributed with this software.
7 #-----------------------------------------------------------------------------
8 '''
9 
10 '''
11 
12 #-----------------------------------------------------------------------------
13 # Boilerplate
14 #----------------------------------------------------------------------------
15 from __future__ import absolute_import, division, print_function, unicode_literals
16 
17 import logging
18 log = logging.getLogger(__name__)
19 
20 from bokeh.util.api import public, internal ; public, internal
21 
22 #-----------------------------------------------------------------------------
23 # Imports
24 #-----------------------------------------------------------------------------
25 
26 # Standard library imports
27 from contextlib import contextmanager
28 import re
29 
30 # External imports
31 
32 # Bokeh imports
33 from ..core.templates import AUTOLOAD_JS, AUTOLOAD_TAG, FILE
34 from ..document.document import DEFAULT_TITLE, Document
35 from ..model import Model
36 from ..settings import settings
37 from ..util.compiler import bundle_all_models
38 from ..util.string import encode_utf8
39 from .bundle import bundle_for_objs_and_resources
40 from .util import FromCurdoc
41 from .util import (check_models_or_docs, check_one_model_or_doc, div_for_render_item, find_existing_docs, html_page_for_render_items,
42                    script_for_render_items, standalone_docs_json_and_render_items, wrap_in_onload, wrap_in_script_tag)
43 
44 #-----------------------------------------------------------------------------
45 # Globals and constants
46 #-----------------------------------------------------------------------------
47 
48 #-----------------------------------------------------------------------------
49 # Public API
50 #-----------------------------------------------------------------------------
51 
52 @public((1,0,0))
53 def autoload_static(model, resources, script_path):
54     ''' Return JavaScript code and a script tag that can be used to embed
55     Bokeh Plots.
56 
57     The data for the plot is stored directly in the returned JavaScript code.
58 
59     Args:
60         model (Model or Document) :
61 
62         resources (Resources) :
63 
64         script_path (str) :
65 
66     Returns:
67         (js, tag) :
68             JavaScript code to be saved at ``script_path`` and a ``<script>``
69             tag to load it
70 
71     Raises:
72         ValueError
73 
74     '''
75     # TODO: maybe warn that it's not exactly useful, but technically possible
76     # if resources.mode == 'inline':
77     #     raise ValueError("autoload_static() requires non-inline resources")
78 
79     model = check_one_model_or_doc(model)
80 
81     with _ModelInDocument([model]):
82         (docs_json, render_items) = standalone_docs_json_and_render_items([model])
83 
84     bundle = bundle_all_models()
85     script = script_for_render_items(docs_json, render_items)
86     item = render_items[0]
87 
88     js = wrap_in_onload(AUTOLOAD_JS.render(
89         js_urls = resources.js_files,
90         css_urls = resources.css_files,
91         js_raw = resources.js_raw + [bundle, script],
92         css_raw = resources.css_raw_str,
93         elementid = item['elementid'],
94     ))
95 
96     tag = AUTOLOAD_TAG.render(
97         src_path = script_path,
98         elementid = item['elementid'],
99         modelid = item.get('modelid', ''),
100         docid = item.get('docid', ''),
101     )
102 
103     return encode_utf8(js), encode_utf8(tag)
104 
105 @public((1,0,0))
106 def components(models, wrap_script=True, wrap_plot_info=True, theme=FromCurdoc):
107     ''' Return HTML components to embed a Bokeh plot. The data for the plot is
108     stored directly in the returned HTML.
109 
110     An example can be found in examples/embed/embed_multiple.py
111 
112     .. note::
113         The returned components assume that BokehJS resources are
114         **already loaded**.
115 
116     Args:
117         models (Model|list|dict|tuple) :
118             A single Model, a list/tuple of Models, or a dictionary of keys and Models.
119 
120         wrap_script (boolean, optional) :
121             If True, the returned javascript is wrapped in a script tag.
122             (default: True)
123 
124         wrap_plot_info (boolean, optional) : If True, returns ``<div>`` strings.
125             Otherwise, return dicts that can be used to build your own divs.
126             (default: True)
127 
128             If False, the returned dictionary contains the following information:
129 
130             .. code-block:: python
131 
132                 {
133                     'modelid':  'The model ID, used with Document.get_model_by_id',
134                     'elementid': 'The css identifier the BokehJS will look for to target the plot',
135                     'docid': 'Used by Bokeh to find the doc embedded in the returned script',
136                 }
137 
138         theme (Theme, optional) :
139             Defaults to the ``Theme`` instance in the current document.
140             Setting this to ``None`` uses the default theme or the theme
141             already specified in the document. Any other value must be an
142             instance of the ``Theme`` class.
143 
144     Returns:
145         UTF-8 encoded *(script, div[s])* or *(raw_script, plot_info[s])*
146 
147     Examples:
148 
149         With default wrapping parameter values:
150 
151         .. code-block:: python
152 
153             components(plot)
154             # => (script, plot_div)
155 
156             components((plot1, plot2))
157             # => (script, (plot1_div, plot2_div))
158 
159             components({"Plot 1": plot1, "Plot 2": plot2})
160             # => (script, {"Plot 1": plot1_div, "Plot 2": plot2_div})
161 
162     Examples:
163 
164         With wrapping parameters set to ``False``:
165 
166         .. code-block:: python
167 
168             components(plot, wrap_script=False, wrap_plot_info=False)
169             # => (javascript, plot_dict)
170 
171             components((plot1, plot2), wrap_script=False, wrap_plot_info=False)
172             # => (javascript, (plot1_dict, plot2_dict))
173 
174             components({"Plot 1": plot1, "Plot 2": plot2}, wrap_script=False, wrap_plot_info=False)
175             # => (javascript, {"Plot 1": plot1_dict, "Plot 2": plot2_dict})
176 
177     '''
178     # 1) Convert single items and dicts into list
179 
180     was_single_object = isinstance(models, Model) or isinstance(models, Document)
181     # converts single to list
182     models = check_models_or_docs(models, allow_dict=True)
183     # now convert dict to list, saving keys in the same order
184     model_keys = None
185     if isinstance(models, dict):
186         model_keys = models.keys()
187         values = []
188         # don't just use .values() to ensure we are in the same order as key list
189         for k in model_keys:
190             values.append(models[k])
191         models = values
192 
193     # 2) Append models to one document. Either pre-existing or new and render
194     with _ModelInDocument(models, apply_theme=theme):
195         (docs_json, render_items) = standalone_docs_json_and_render_items(models)
196 
197     script  = bundle_all_models()
198     script += script_for_render_items(docs_json, render_items)
199     if wrap_script:
200         script = wrap_in_script_tag(script)
201     script = encode_utf8(script)
202 
203     if wrap_plot_info:
204         results = list(div_for_render_item(item) for item in render_items)
205     else:
206         results = render_items
207 
208     # 3) convert back to the input shape
209 
210     if was_single_object:
211         return script, results[0]
212     elif model_keys is not None:
213         result = {}
214         for (key, value) in zip(model_keys, results):
215             result[key] = value
216         return script, result
217     else:
218         return script, tuple(results)
219 
220 @public((1,0,0))
221 def file_html(models,
222               resources,
223               title=None,
224               template=FILE,
225               template_variables={},
226               theme=FromCurdoc):
227     ''' Return an HTML document that embeds Bokeh Model or Document objects.
228 
229     The data for the plot is stored directly in the returned HTML, with
230     support for customizing the JS/CSS resources independently and
231     customizing the jinja2 template.
232 
233     Args:
234         models (Model or Document or list) : Bokeh object or objects to render
235             typically a Model or Document
236 
237         resources (Resources or tuple(JSResources or None, CSSResources or None)) : i
238             A resource configuration for Bokeh JS & CSS assets.
239 
240         title (str, optional) : a title for the HTML document ``<title>`` tags or None. (default: None)
241             If None, attempt to automatically find the Document title from the given plot objects.
242 
243         template (Template, optional) : HTML document template (default: FILE)
244             A Jinja2 Template, see bokeh.core.templates.FILE for the required
245             template parameters
246 
247         template_variables (dict, optional) : variables to be used in the Jinja2
248             template. If used, the following variable names will be overwritten:
249             title, bokeh_js, bokeh_css, plot_script, plot_div
250 
251         theme (Theme, optional) :
252             Defaults to the ``Theme`` instance in the current document.
253             Setting this to ``None`` uses the default theme or the theme
254             already specified in the document. Any other value must be an
255             instance of the ``Theme`` class.
256 
257     Returns:
258         UTF-8 encoded HTML
259 
260     '''
261     models = check_models_or_docs(models)
262 
263     with _ModelInDocument(models, apply_theme=theme):
264         (docs_json, render_items) = standalone_docs_json_and_render_items(models)
265         title = _title_from_models(models, title)
266         bundle = bundle_for_objs_and_resources(models, resources)
267         return html_page_for_render_items(bundle, docs_json, render_items, title=title,
268                                            template=template, template_variables=template_variables)
269 
270 #-----------------------------------------------------------------------------
271 # Internal API
272 #-----------------------------------------------------------------------------
273 
274 #-----------------------------------------------------------------------------
275 # Private API
276 #-----------------------------------------------------------------------------
277 
278 @contextmanager
279 def _ModelInDocument(models, apply_theme=None):
280     doc = find_existing_docs(models)
281     old_theme = doc.theme
282 
283     if apply_theme is FromCurdoc:
284         from ..io import curdoc; curdoc
285         doc.theme = curdoc().theme
286     elif apply_theme is not None:
287         doc.theme = apply_theme
288 
289     models_to_dedoc = _add_doc_to_models(doc, models)
290 
291     if settings.perform_document_validation():
292         doc.validate()
293 
294     yield doc
295 
296     for model in models_to_dedoc:
297         doc.remove_root(model, apply_theme)
298     doc.theme = old_theme
299 
300 def _add_doc_to_models(doc, models):
301     models_to_dedoc = []
302     for model in models:
303         if isinstance(model, Model):
304             if model.document is None:
305                 try:
306                     doc.add_root(model)
307                     models_to_dedoc.append(model)
308                 except RuntimeError as e:
309                     child = re.search('\((.*)\)', str(e)).group(0)
310                     msg = ('Sub-model {0} of the root model {1} is already owned '
311                            'by another document (Models must be owned by only a '
312                            'single document). This may indicate a usage '
313                            'error.'.format(child, model))
314                     raise RuntimeError(msg)
315     return models_to_dedoc
316 
317 def _title_from_models(models, title):
318     # use override title
319     if title is not None:
320         return title
321 
322     # use title from any listed document
323     for p in models:
324         if isinstance(p, Document):
325             return p.title
326 
327     # use title from any model's document
328     for p in models:
329         if p.document is not None:
330             return p.document.title
331 
332     # use default title
333     return DEFAULT_TITLE
334 
335 #-----------------------------------------------------------------------------
336 # Code
337 #-----------------------------------------------------------------------------
338
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bokeh/embed/standalone.py b/bokeh/embed/standalone.py
--- a/bokeh/embed/standalone.py
+++ b/bokeh/embed/standalone.py
@@ -109,9 +109,25 @@
 
     An example can be found in examples/embed/embed_multiple.py
 
-    .. note::
-        The returned components assume that BokehJS resources are
-        **already loaded**.
+    The returned components assume that BokehJS resources are **already loaded**.
+    The html template in which they will be embedded needs to include the following
+    links and scripts tags. The widgets and tables resources are only necessary if
+    the components make use of widgets and tables.
+    
+    .. code-block:: html
+        <link
+            href="http://cdn.pydata.org/bokeh/release/bokeh-x.y.z.min.css"
+            rel="stylesheet" type="text/css">
+        <link
+            href="http://cdn.pydata.org/bokeh/release/bokeh-widgets-x.y.z.min.css"
+            rel="stylesheet" type="text/css">
+        <link
+            href="http://cdn.pydata.org/bokeh/release/bokeh-tables-x.y.z.min.css"
+            rel="stylesheet" type="text/css">
+
+        <script src="http://cdn.pydata.org/bokeh/release/bokeh-x.y.z.min.js"></script>
+        <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>
 
     Args:
         models (Model|list|dict|tuple) :

{"golden_diff": "diff --git a/bokeh/embed/standalone.py b/bokeh/embed/standalone.py\n--- a/bokeh/embed/standalone.py\n+++ b/bokeh/embed/standalone.py\n@@ -109,9 +109,25 @@\n \n     An example can be found in examples/embed/embed_multiple.py\n \n-    .. note::\n-        The returned components assume that BokehJS resources are\n-        **already loaded**.\n+    The returned components assume that BokehJS resources are **already loaded**.\n+    The html template in which they will be embedded needs to include the following\n+    links and scripts tags. The widgets and tables resources are only necessary if\n+    the components make use of widgets and tables.\n+    \n+    .. code-block:: html\n+        <link\n+            href=\"http://cdn.pydata.org/bokeh/release/bokeh-x.y.z.min.css\"\n+            rel=\"stylesheet\" type=\"text/css\">\n+        <link\n+            href=\"http://cdn.pydata.org/bokeh/release/bokeh-widgets-x.y.z.min.css\"\n+            rel=\"stylesheet\" type=\"text/css\">\n+        <link\n+            href=\"http://cdn.pydata.org/bokeh/release/bokeh-tables-x.y.z.min.css\"\n+            rel=\"stylesheet\" type=\"text/css\">\n+\n+        <script src=\"http://cdn.pydata.org/bokeh/release/bokeh-x.y.z.min.js\"></script>\n+        <script src=\"http://cdn.pydata.org/bokeh/release/bokeh-widgets-x.y.z.min.js\"></script>\n+        <script src=\"http://cdn.pydata.org/bokeh/release/bokeh-tables-x.y.z.min.js\"></script>\n \n     Args:\n         models (Model|list|dict|tuple) :\n", "issue": "Incomplete docs re embedding when using data tables\nHi, I banged my head a bit trying to use `components` to render tables and failing while `file_html` would work well.\r\nTurns out we now need to include: \r\n```html\r\n<link rel=\"stylesheet\" href=\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.9.min.css\" type=\"text/css\" />\r\n<script type=\"text/javascript\" src=\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.9.min.js\"></script>\r\n```\r\nin order for data tables to render properly and this is not mentioned in the embed sections of the User Guide or the Reference.\r\n\r\nHaving a look right now how the docs are built to see if I can provide help with a PR if that's not fixed already.\r\n\r\nEDIT: Going through the docs to prepare a PR, I read in the 0.12.7 release notes that the change should be transparent as Bokeh would load the `-tables` resources automatically when necessary. It wasn't the case for me. But maybe it wasn't meant for the `components` use case?\r\n\r\nI will provide a PR later today. Just waiting for a feedback on that last question to see whether this paragraph in the 0.12.7 release notes should be reworded if `components` is not covered by the automatic process.\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2012 - 2017, Anaconda, Inc. All rights reserved.\n#\n# Powered by the Bokeh Development Team.\n#\n# The full license is in the file LICENSE.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n'''\n\n'''\n\n#-----------------------------------------------------------------------------\n# Boilerplate\n#----------------------------------------------------------------------------\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport logging\nlog = logging.getLogger(__name__)\n\nfrom bokeh.util.api import public, internal ; public, internal\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\n\n# Standard library imports\nfrom contextlib import contextmanager\nimport re\n\n# External imports\n\n# Bokeh imports\nfrom ..core.templates import AUTOLOAD_JS, AUTOLOAD_TAG, FILE\nfrom ..document.document import DEFAULT_TITLE, Document\nfrom ..model import Model\nfrom ..settings import settings\nfrom ..util.compiler import bundle_all_models\nfrom ..util.string import encode_utf8\nfrom .bundle import bundle_for_objs_and_resources\nfrom .util import FromCurdoc\nfrom .util import (check_models_or_docs, check_one_model_or_doc, div_for_render_item, find_existing_docs, html_page_for_render_items,\n                   script_for_render_items, standalone_docs_json_and_render_items, wrap_in_onload, wrap_in_script_tag)\n\n#-----------------------------------------------------------------------------\n# Globals and constants\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Public API\n#-----------------------------------------------------------------------------\n\n@public((1,0,0))\ndef autoload_static(model, resources, script_path):\n    ''' Return JavaScript code and a script tag that can be used to embed\n    Bokeh Plots.\n\n    The data for the plot is stored directly in the returned JavaScript code.\n\n    Args:\n        model (Model or Document) :\n\n        resources (Resources) :\n\n        script_path (str) :\n\n    Returns:\n        (js, tag) :\n            JavaScript code to be saved at ``script_path`` and a ``<script>``\n            tag to load it\n\n    Raises:\n        ValueError\n\n    '''\n    # TODO: maybe warn that it's not exactly useful, but technically possible\n    # if resources.mode == 'inline':\n    #     raise ValueError(\"autoload_static() requires non-inline resources\")\n\n    model = check_one_model_or_doc(model)\n\n    with _ModelInDocument([model]):\n        (docs_json, render_items) = standalone_docs_json_and_render_items([model])\n\n    bundle = bundle_all_models()\n    script = script_for_render_items(docs_json, render_items)\n    item = render_items[0]\n\n    js = wrap_in_onload(AUTOLOAD_JS.render(\n        js_urls = resources.js_files,\n        css_urls = resources.css_files,\n        js_raw = resources.js_raw + [bundle, script],\n        css_raw = resources.css_raw_str,\n        elementid = item['elementid'],\n    ))\n\n    tag = AUTOLOAD_TAG.render(\n        src_path = script_path,\n        elementid = item['elementid'],\n        modelid = item.get('modelid', ''),\n        docid = item.get('docid', ''),\n    )\n\n    return encode_utf8(js), encode_utf8(tag)\n\n@public((1,0,0))\ndef components(models, wrap_script=True, wrap_plot_info=True, theme=FromCurdoc):\n    ''' Return HTML components to embed a Bokeh plot. The data for the plot is\n    stored directly in the returned HTML.\n\n    An example can be found in examples/embed/embed_multiple.py\n\n    .. note::\n        The returned components assume that BokehJS resources are\n        **already loaded**.\n\n    Args:\n        models (Model|list|dict|tuple) :\n            A single Model, a list/tuple of Models, or a dictionary of keys and Models.\n\n        wrap_script (boolean, optional) :\n            If True, the returned javascript is wrapped in a script tag.\n            (default: True)\n\n        wrap_plot_info (boolean, optional) : If True, returns ``<div>`` strings.\n            Otherwise, return dicts that can be used to build your own divs.\n            (default: True)\n\n            If False, the returned dictionary contains the following information:\n\n            .. code-block:: python\n\n                {\n                    'modelid':  'The model ID, used with Document.get_model_by_id',\n                    'elementid': 'The css identifier the BokehJS will look for to target the plot',\n                    'docid': 'Used by Bokeh to find the doc embedded in the returned script',\n                }\n\n        theme (Theme, optional) :\n            Defaults to the ``Theme`` instance in the current document.\n            Setting this to ``None`` uses the default theme or the theme\n            already specified in the document. Any other value must be an\n            instance of the ``Theme`` class.\n\n    Returns:\n        UTF-8 encoded *(script, div[s])* or *(raw_script, plot_info[s])*\n\n    Examples:\n\n        With default wrapping parameter values:\n\n        .. code-block:: python\n\n            components(plot)\n            # => (script, plot_div)\n\n            components((plot1, plot2))\n            # => (script, (plot1_div, plot2_div))\n\n            components({\"Plot 1\": plot1, \"Plot 2\": plot2})\n            # => (script, {\"Plot 1\": plot1_div, \"Plot 2\": plot2_div})\n\n    Examples:\n\n        With wrapping parameters set to ``False``:\n\n        .. code-block:: python\n\n            components(plot, wrap_script=False, wrap_plot_info=False)\n            # => (javascript, plot_dict)\n\n            components((plot1, plot2), wrap_script=False, wrap_plot_info=False)\n            # => (javascript, (plot1_dict, plot2_dict))\n\n            components({\"Plot 1\": plot1, \"Plot 2\": plot2}, wrap_script=False, wrap_plot_info=False)\n            # => (javascript, {\"Plot 1\": plot1_dict, \"Plot 2\": plot2_dict})\n\n    '''\n    # 1) Convert single items and dicts into list\n\n    was_single_object = isinstance(models, Model) or isinstance(models, Document)\n    # converts single to list\n    models = check_models_or_docs(models, allow_dict=True)\n    # now convert dict to list, saving keys in the same order\n    model_keys = None\n    if isinstance(models, dict):\n        model_keys = models.keys()\n        values = []\n        # don't just use .values() to ensure we are in the same order as key list\n        for k in model_keys:\n            values.append(models[k])\n        models = values\n\n    # 2) Append models to one document. Either pre-existing or new and render\n    with _ModelInDocument(models, apply_theme=theme):\n        (docs_json, render_items) = standalone_docs_json_and_render_items(models)\n\n    script  = bundle_all_models()\n    script += script_for_render_items(docs_json, render_items)\n    if wrap_script:\n        script = wrap_in_script_tag(script)\n    script = encode_utf8(script)\n\n    if wrap_plot_info:\n        results = list(div_for_render_item(item) for item in render_items)\n    else:\n        results = render_items\n\n    # 3) convert back to the input shape\n\n    if was_single_object:\n        return script, results[0]\n    elif model_keys is not None:\n        result = {}\n        for (key, value) in zip(model_keys, results):\n            result[key] = value\n        return script, result\n    else:\n        return script, tuple(results)\n\n@public((1,0,0))\ndef file_html(models,\n              resources,\n              title=None,\n              template=FILE,\n              template_variables={},\n              theme=FromCurdoc):\n    ''' Return an HTML document that embeds Bokeh Model or Document objects.\n\n    The data for the plot is stored directly in the returned HTML, with\n    support for customizing the JS/CSS resources independently and\n    customizing the jinja2 template.\n\n    Args:\n        models (Model or Document or list) : Bokeh object or objects to render\n            typically a Model or Document\n\n        resources (Resources or tuple(JSResources or None, CSSResources or None)) : i\n            A resource configuration for Bokeh JS & CSS assets.\n\n        title (str, optional) : a title for the HTML document ``<title>`` tags or None. (default: None)\n            If None, attempt to automatically find the Document title from the given plot objects.\n\n        template (Template, optional) : HTML document template (default: FILE)\n            A Jinja2 Template, see bokeh.core.templates.FILE for the required\n            template parameters\n\n        template_variables (dict, optional) : variables to be used in the Jinja2\n            template. If used, the following variable names will be overwritten:\n            title, bokeh_js, bokeh_css, plot_script, plot_div\n\n        theme (Theme, optional) :\n            Defaults to the ``Theme`` instance in the current document.\n            Setting this to ``None`` uses the default theme or the theme\n            already specified in the document. Any other value must be an\n            instance of the ``Theme`` class.\n\n    Returns:\n        UTF-8 encoded HTML\n\n    '''\n    models = check_models_or_docs(models)\n\n    with _ModelInDocument(models, apply_theme=theme):\n        (docs_json, render_items) = standalone_docs_json_and_render_items(models)\n        title = _title_from_models(models, title)\n        bundle = bundle_for_objs_and_resources(models, resources)\n        return html_page_for_render_items(bundle, docs_json, render_items, title=title,\n                                           template=template, template_variables=template_variables)\n\n#-----------------------------------------------------------------------------\n# Internal API\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Private API\n#-----------------------------------------------------------------------------\n\n@contextmanager\ndef _ModelInDocument(models, apply_theme=None):\n    doc = find_existing_docs(models)\n    old_theme = doc.theme\n\n    if apply_theme is FromCurdoc:\n        from ..io import curdoc; curdoc\n        doc.theme = curdoc().theme\n    elif apply_theme is not None:\n        doc.theme = apply_theme\n\n    models_to_dedoc = _add_doc_to_models(doc, models)\n\n    if settings.perform_document_validation():\n        doc.validate()\n\n    yield doc\n\n    for model in models_to_dedoc:\n        doc.remove_root(model, apply_theme)\n    doc.theme = old_theme\n\ndef _add_doc_to_models(doc, models):\n    models_to_dedoc = []\n    for model in models:\n        if isinstance(model, Model):\n            if model.document is None:\n                try:\n                    doc.add_root(model)\n                    models_to_dedoc.append(model)\n                except RuntimeError as e:\n                    child = re.search('\\((.*)\\)', str(e)).group(0)\n                    msg = ('Sub-model {0} of the root model {1} is already owned '\n                           'by another document (Models must be owned by only a '\n                           'single document). This may indicate a usage '\n                           'error.'.format(child, model))\n                    raise RuntimeError(msg)\n    return models_to_dedoc\n\ndef _title_from_models(models, title):\n    # use override title\n    if title is not None:\n        return title\n\n    # use title from any listed document\n    for p in models:\n        if isinstance(p, Document):\n            return p.title\n\n    # use title from any model's document\n    for p in models:\n        if p.document is not None:\n            return p.document.title\n\n    # use default title\n    return DEFAULT_TITLE\n\n#-----------------------------------------------------------------------------\n# Code\n#-----------------------------------------------------------------------------\n", "path": "bokeh/embed/standalone.py"}], "after_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2012 - 2017, Anaconda, Inc. All rights reserved.\n#\n# Powered by the Bokeh Development Team.\n#\n# The full license is in the file LICENSE.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n'''\n\n'''\n\n#-----------------------------------------------------------------------------\n# Boilerplate\n#----------------------------------------------------------------------------\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport logging\nlog = logging.getLogger(__name__)\n\nfrom bokeh.util.api import public, internal ; public, internal\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\n\n# Standard library imports\nfrom contextlib import contextmanager\nimport re\n\n# External imports\n\n# Bokeh imports\nfrom ..core.templates import AUTOLOAD_JS, AUTOLOAD_TAG, FILE\nfrom ..document.document import DEFAULT_TITLE, Document\nfrom ..model import Model\nfrom ..settings import settings\nfrom ..util.compiler import bundle_all_models\nfrom ..util.string import encode_utf8\nfrom .bundle import bundle_for_objs_and_resources\nfrom .util import FromCurdoc\nfrom .util import (check_models_or_docs, check_one_model_or_doc, div_for_render_item, find_existing_docs, html_page_for_render_items,\n                   script_for_render_items, standalone_docs_json_and_render_items, wrap_in_onload, wrap_in_script_tag)\n\n#-----------------------------------------------------------------------------\n# Globals and constants\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Public API\n#-----------------------------------------------------------------------------\n\n@public((1,0,0))\ndef autoload_static(model, resources, script_path):\n    ''' Return JavaScript code and a script tag that can be used to embed\n    Bokeh Plots.\n\n    The data for the plot is stored directly in the returned JavaScript code.\n\n    Args:\n        model (Model or Document) :\n\n        resources (Resources) :\n\n        script_path (str) :\n\n    Returns:\n        (js, tag) :\n            JavaScript code to be saved at ``script_path`` and a ``<script>``\n            tag to load it\n\n    Raises:\n        ValueError\n\n    '''\n    # TODO: maybe warn that it's not exactly useful, but technically possible\n    # if resources.mode == 'inline':\n    #     raise ValueError(\"autoload_static() requires non-inline resources\")\n\n    model = check_one_model_or_doc(model)\n\n    with _ModelInDocument([model]):\n        (docs_json, render_items) = standalone_docs_json_and_render_items([model])\n\n    bundle = bundle_all_models()\n    script = script_for_render_items(docs_json, render_items)\n    item = render_items[0]\n\n    js = wrap_in_onload(AUTOLOAD_JS.render(\n        js_urls = resources.js_files,\n        css_urls = resources.css_files,\n        js_raw = resources.js_raw + [bundle, script],\n        css_raw = resources.css_raw_str,\n        elementid = item['elementid'],\n    ))\n\n    tag = AUTOLOAD_TAG.render(\n        src_path = script_path,\n        elementid = item['elementid'],\n        modelid = item.get('modelid', ''),\n        docid = item.get('docid', ''),\n    )\n\n    return encode_utf8(js), encode_utf8(tag)\n\n@public((1,0,0))\ndef components(models, wrap_script=True, wrap_plot_info=True, theme=FromCurdoc):\n    ''' Return HTML components to embed a Bokeh plot. The data for the plot is\n    stored directly in the returned HTML.\n\n    An example can be found in examples/embed/embed_multiple.py\n\n    The returned components assume that BokehJS resources are **already loaded**.\n    The html template in which they will be embedded needs to include the following\n    links and scripts tags. The widgets and tables resources are only necessary if\n    the components make use of widgets and tables.\n    \n    .. code-block:: html\n        <link\n            href=\"http://cdn.pydata.org/bokeh/release/bokeh-x.y.z.min.css\"\n            rel=\"stylesheet\" type=\"text/css\">\n        <link\n            href=\"http://cdn.pydata.org/bokeh/release/bokeh-widgets-x.y.z.min.css\"\n            rel=\"stylesheet\" type=\"text/css\">\n        <link\n            href=\"http://cdn.pydata.org/bokeh/release/bokeh-tables-x.y.z.min.css\"\n            rel=\"stylesheet\" type=\"text/css\">\n\n        <script src=\"http://cdn.pydata.org/bokeh/release/bokeh-x.y.z.min.js\"></script>\n        <script src=\"http://cdn.pydata.org/bokeh/release/bokeh-widgets-x.y.z.min.js\"></script>\n        <script src=\"http://cdn.pydata.org/bokeh/release/bokeh-tables-x.y.z.min.js\"></script>\n\n    Args:\n        models (Model|list|dict|tuple) :\n            A single Model, a list/tuple of Models, or a dictionary of keys and Models.\n\n        wrap_script (boolean, optional) :\n            If True, the returned javascript is wrapped in a script tag.\n            (default: True)\n\n        wrap_plot_info (boolean, optional) : If True, returns ``<div>`` strings.\n            Otherwise, return dicts that can be used to build your own divs.\n            (default: True)\n\n            If False, the returned dictionary contains the following information:\n\n            .. code-block:: python\n\n                {\n                    'modelid':  'The model ID, used with Document.get_model_by_id',\n                    'elementid': 'The css identifier the BokehJS will look for to target the plot',\n                    'docid': 'Used by Bokeh to find the doc embedded in the returned script',\n                }\n\n        theme (Theme, optional) :\n            Defaults to the ``Theme`` instance in the current document.\n            Setting this to ``None`` uses the default theme or the theme\n            already specified in the document. Any other value must be an\n            instance of the ``Theme`` class.\n\n    Returns:\n        UTF-8 encoded *(script, div[s])* or *(raw_script, plot_info[s])*\n\n    Examples:\n\n        With default wrapping parameter values:\n\n        .. code-block:: python\n\n            components(plot)\n            # => (script, plot_div)\n\n            components((plot1, plot2))\n            # => (script, (plot1_div, plot2_div))\n\n            components({\"Plot 1\": plot1, \"Plot 2\": plot2})\n            # => (script, {\"Plot 1\": plot1_div, \"Plot 2\": plot2_div})\n\n    Examples:\n\n        With wrapping parameters set to ``False``:\n\n        .. code-block:: python\n\n            components(plot, wrap_script=False, wrap_plot_info=False)\n            # => (javascript, plot_dict)\n\n            components((plot1, plot2), wrap_script=False, wrap_plot_info=False)\n            # => (javascript, (plot1_dict, plot2_dict))\n\n            components({\"Plot 1\": plot1, \"Plot 2\": plot2}, wrap_script=False, wrap_plot_info=False)\n            # => (javascript, {\"Plot 1\": plot1_dict, \"Plot 2\": plot2_dict})\n\n    '''\n    # 1) Convert single items and dicts into list\n\n    was_single_object = isinstance(models, Model) or isinstance(models, Document)\n    # converts single to list\n    models = check_models_or_docs(models, allow_dict=True)\n    # now convert dict to list, saving keys in the same order\n    model_keys = None\n    if isinstance(models, dict):\n        model_keys = models.keys()\n        values = []\n        # don't just use .values() to ensure we are in the same order as key list\n        for k in model_keys:\n            values.append(models[k])\n        models = values\n\n    # 2) Append models to one document. Either pre-existing or new and render\n    with _ModelInDocument(models, apply_theme=theme):\n        (docs_json, render_items) = standalone_docs_json_and_render_items(models)\n\n    script  = bundle_all_models()\n    script += script_for_render_items(docs_json, render_items)\n    if wrap_script:\n        script = wrap_in_script_tag(script)\n    script = encode_utf8(script)\n\n    if wrap_plot_info:\n        results = list(div_for_render_item(item) for item in render_items)\n    else:\n        results = render_items\n\n    # 3) convert back to the input shape\n\n    if was_single_object:\n        return script, results[0]\n    elif model_keys is not None:\n        result = {}\n        for (key, value) in zip(model_keys, results):\n            result[key] = value\n        return script, result\n    else:\n        return script, tuple(results)\n\n@public((1,0,0))\ndef file_html(models,\n              resources,\n              title=None,\n              template=FILE,\n              template_variables={},\n              theme=FromCurdoc):\n    ''' Return an HTML document that embeds Bokeh Model or Document objects.\n\n    The data for the plot is stored directly in the returned HTML, with\n    support for customizing the JS/CSS resources independently and\n    customizing the jinja2 template.\n\n    Args:\n        models (Model or Document or list) : Bokeh object or objects to render\n            typically a Model or Document\n\n        resources (Resources or tuple(JSResources or None, CSSResources or None)) : i\n            A resource configuration for Bokeh JS & CSS assets.\n\n        title (str, optional) : a title for the HTML document ``<title>`` tags or None. (default: None)\n            If None, attempt to automatically find the Document title from the given plot objects.\n\n        template (Template, optional) : HTML document template (default: FILE)\n            A Jinja2 Template, see bokeh.core.templates.FILE for the required\n            template parameters\n\n        template_variables (dict, optional) : variables to be used in the Jinja2\n            template. If used, the following variable names will be overwritten:\n            title, bokeh_js, bokeh_css, plot_script, plot_div\n\n        theme (Theme, optional) :\n            Defaults to the ``Theme`` instance in the current document.\n            Setting this to ``None`` uses the default theme or the theme\n            already specified in the document. Any other value must be an\n            instance of the ``Theme`` class.\n\n    Returns:\n        UTF-8 encoded HTML\n\n    '''\n    models = check_models_or_docs(models)\n\n    with _ModelInDocument(models, apply_theme=theme):\n        (docs_json, render_items) = standalone_docs_json_and_render_items(models)\n        title = _title_from_models(models, title)\n        bundle = bundle_for_objs_and_resources(models, resources)\n        return html_page_for_render_items(bundle, docs_json, render_items, title=title,\n                                           template=template, template_variables=template_variables)\n\n#-----------------------------------------------------------------------------\n# Internal API\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Private API\n#-----------------------------------------------------------------------------\n\n@contextmanager\ndef _ModelInDocument(models, apply_theme=None):\n    doc = find_existing_docs(models)\n    old_theme = doc.theme\n\n    if apply_theme is FromCurdoc:\n        from ..io import curdoc; curdoc\n        doc.theme = curdoc().theme\n    elif apply_theme is not None:\n        doc.theme = apply_theme\n\n    models_to_dedoc = _add_doc_to_models(doc, models)\n\n    if settings.perform_document_validation():\n        doc.validate()\n\n    yield doc\n\n    for model in models_to_dedoc:\n        doc.remove_root(model, apply_theme)\n    doc.theme = old_theme\n\ndef _add_doc_to_models(doc, models):\n    models_to_dedoc = []\n    for model in models:\n        if isinstance(model, Model):\n            if model.document is None:\n                try:\n                    doc.add_root(model)\n                    models_to_dedoc.append(model)\n                except RuntimeError as e:\n                    child = re.search('\\((.*)\\)', str(e)).group(0)\n                    msg = ('Sub-model {0} of the root model {1} is already owned '\n                           'by another document (Models must be owned by only a '\n                           'single document). This may indicate a usage '\n                           'error.'.format(child, model))\n                    raise RuntimeError(msg)\n    return models_to_dedoc\n\ndef _title_from_models(models, title):\n    # use override title\n    if title is not None:\n        return title\n\n    # use title from any listed document\n    for p in models:\n        if isinstance(p, Document):\n            return p.title\n\n    # use title from any model's document\n    for p in models:\n        if p.document is not None:\n            return p.document.title\n\n    # use default title\n    return DEFAULT_TITLE\n\n#-----------------------------------------------------------------------------\n# Code\n#-----------------------------------------------------------------------------\n", "path": "bokeh/embed/standalone.py"}]}