Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure perspective-viewer is loaded before rendering #6696

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading