-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: altair did not work in Jupyter Lab because requirejs was not loa…
…ded.
- Loading branch information
1 parent
d05826c
commit 416557f
Showing
1 changed file
with
38 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,32 @@ | |
<script> | ||
module.exports = { | ||
created() { | ||
requirejs.undef("vega") | ||
requirejs.undef("vega-lite") | ||
requirejs.undef("vega-embed") | ||
require.config({ | ||
map: { | ||
'*': { | ||
'vega': `${this.getCdn()}/vega@5/build/vega.min.js`, | ||
'vega-lite': `${this.getCdn()}/[email protected]/build/vega-lite.min.js`, | ||
'vega-embed': `${this.getCdn()}/vega-embed@6/build/vega-embed.min.js`, | ||
this.vegaLoaded = (async () => { | ||
await this.loadRequire(); | ||
requirejs.undef("vega") | ||
requirejs.undef("vega-lite") | ||
requirejs.undef("vega-embed") | ||
require.config({ | ||
map: { | ||
'*': { | ||
'vega': `${this.getCdn()}/vega@5/build/vega.min.js`, | ||
'vega-lite': `${this.getCdn()}/vega-lite@5/build/vega-lite.min.js`, | ||
'vega-embed': `${this.getCdn()}/vega-embed@6/build/vega-embed.min.js`, | ||
} | ||
} | ||
}) | ||
// pre load | ||
await new Promise((resolve, reject) => { | ||
require(['vega', 'vega-lite', 'vega-embed'], () => { | ||
resolve() | ||
}, reject) | ||
} | ||
}) | ||
// pre load | ||
require(['vega', 'vega-lite', 'vega-embed'], () => { | ||
}) | ||
this.do_plot_debounced = _.debounce(() => this.do_plot(), 100) | ||
); | ||
})(); | ||
this.do_plot_debounced = _.debounce(async () => { | ||
await this.vegaLoaded; | ||
this.do_plot() | ||
}, 100) | ||
}, | ||
mounted() { | ||
this.do_plot_debounced(); | ||
|
@@ -64,6 +74,20 @@ module.exports = { | |
})(); | ||
}); | ||
}, | ||
loadRequire() { | ||
/* Needed in lab */ | ||
if (window.requirejs) { | ||
console.log('require found'); | ||
return Promise.resolve() | ||
} | ||
return new Promise((resolve, reject) => { | ||
const script = document.createElement('script'); | ||
script.src = `${this.getCdn()}/[email protected]/require.js`; | ||
script.onload = resolve; | ||
script.onerror = reject; | ||
document.head.appendChild(script); | ||
}); | ||
}, | ||
getBaseUrl() { | ||
if (window.solara && window.solara.rootPath !== undefined) { | ||
return solara.rootPath + "/"; | ||
|