Skip to content

Commit

Permalink
Ensure perspective-viewer is loaded before rendering (#6696)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Apr 9, 2024
1 parent 0da615e commit ee07ee4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion panel/_templates/autoload_panel_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ calls it with the rendered model.
}

{%- for lib, urls in skip_imports.items() %}
if (((window['{{ lib }}'] !== undefined) && (!(window['{{ lib }}'] instanceof HTMLElement))) || window.requirejs) {
if (((window.{{ lib }} !== undefined) && (!(window.{{ lib }} instanceof HTMLElement))) || window.requirejs) {
var urls = {{ urls }};
for (var i = 0; i < urls.length; i++) {
skip.push(urls[i])
Expand Down
2 changes: 1 addition & 1 deletion panel/_templates/doc_nb_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
function is_loaded(root) {
var Bokeh = get_bokeh(root)
return (Bokeh != null && Bokeh.Panel !== undefined{% for reqs in requirements %} && ({% for req in reqs %}{% if loop.index0 > 0 %}||{% endif %} root['{{ req }}'] !== undefined{% endfor %}){% endfor %}{% if ipywidget %}&& Bokeh.Models._known_models.has("ipywidgets_bokeh.widget.IPyWidget") {% endif %})
return (Bokeh != null && Bokeh.Panel !== undefined{% for reqs in requirements %} && ({% for req in reqs %}{% if loop.index0 > 0 %}||{% endif %} root.{{ req }} !== undefined{% endfor %}){% endfor %}{% if ipywidget %}&& Bokeh.Models._known_models.has("ipywidgets_bokeh.widget.IPyWidget") {% endif %})
}
if (is_loaded(root)) {
embed_document(root);
Expand Down
8 changes: 6 additions & 2 deletions panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
__version__ = str(param.version.Version(
fpath=__file__, archive_commit="$Format:%h$", reponame="panel"))

_LOCAL_DEV_VERSION = any(v in __version__ for v in ('post', 'dirty')) and not state._is_pyodide
_LOCAL_DEV_VERSION = (
any(v in __version__ for v in ('post', 'dirty'))
and not state._is_pyodide
and 'PANEL_DOC_BUILD' not in os.environ
)

#---------------------------------------------------------------------
# Public API
Expand Down Expand Up @@ -683,7 +687,7 @@ class panel_extension(_pyviz_extension):
'gridstack': ['GridStack'],
'katex': ['katex'],
'mathjax': ['MathJax'],
'perspective': ['perspective.worker'],
'perspective': ["customElements.get('perspective-viewer')"],
'plotly': ['Plotly'],
'tabulator': ['Tabulator'],
'terminal': ['Terminal', 'xtermjs'],
Expand Down
3 changes: 2 additions & 1 deletion panel/models/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ def __javascript_modules__(cls):
@classproperty
def __js_skip__(cls):
return {
"perspective": cls.__javascript_modules__
"customElements.get('perspective-viewer')": cls.__javascript_modules__
}

__js_require__ = {
"paths": {
"perspective": f"{config.npm_cdn}/@finos/perspective@{PERSPECTIVE_VERSION}/dist/cdn/perspective",
"perspective-worker": f"{config.npm_cdn}/@finos/perspective@{PERSPECTIVE_VERSION}/dist/cdn/perspective.worker",
"perspective-viewer": f"{config.npm_cdn}/@finos/perspective-viewer@{PERSPECTIVE_VERSION}/dist/cdn/perspective-viewer",
"perspective-viewer-datagrid": f"{config.npm_cdn}/@finos/perspective-viewer-datagrid@{PERSPECTIVE_VERSION}/dist/cdn/perspective-viewer-datagrid",
"perspective-viewer-d3fc": f"{config.npm_cdn}/@finos/perspective-viewer-d3fc@{PERSPECTIVE_VERSION}/dist/cdn/perspective-viewer-d3fc",
Expand Down

0 comments on commit ee07ee4

Please sign in to comment.