Skip to content

Commit

Permalink
Wait until JS dependency is loaded before rendering (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 13, 2020
1 parent 2b9c98f commit 4eb973e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions panel/_templates/doc_nb_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
var render_items = {{ render_items }};
root.Bokeh.embed.embed_items_notebook(docs_json, render_items);
}
if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined) {
if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined{% for req in requirements %} && root['{{ req }}'] !== undefined {% endfor %}) {
embed_document(root);
} else {
var attempts = 0;
var timer = setInterval(function(root) {
if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined) {
if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined{% for req in requirements %} && root['{{ req }}'] !== undefined{% endfor %}) {
clearInterval(timer);
embed_document(root);
} else if (document.readyState == "complete") {
Expand Down
11 changes: 11 additions & 0 deletions panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,17 @@ class panel_extension(_pyviz_extension):
'echarts': 'panel.models.echarts',
'ipywidgets': 'ipywidgets_bokeh.widget'}

# Check whether these are loaded before rendering
_globals = {
'deckgl': 'deck',
'echarts': 'echarts',
'katex': 'katex',
'mathjax': 'MathJax',
'plotly': 'Plotly',
'vega': 'vega',
'vtk': 'vtk'
}

_loaded_extensions = []

def __call__(self, *args, **params):
Expand Down
4 changes: 4 additions & 0 deletions panel/io/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,19 @@ def render_template(document, comm=None, manager=None):
def render_model(model, comm=None):
if not isinstance(model, Model):
raise ValueError("notebook_content expects a single Model instance")
from ..config import panel_extension as pnext

target = model.ref['id']

(docs_json, [render_item]) = standalone_docs_json_and_render_items([model], True)
div = div_for_render_item(render_item)
render_item = render_item.to_json()
requirements = [pnext._globals[ext] for ext in pnext._loaded_extensions
if ext in pnext._globals]
script = DOC_NB_JS.render(
docs_json=serialize_json(docs_json),
render_items=serialize_json([render_item]),
requirements=requirements
)
bokeh_script, bokeh_div = script, div
html = "<div id='{id}'>{html}</div>".format(id=target, html=bokeh_div)
Expand Down

0 comments on commit 4eb973e

Please sign in to comment.