Skip to content

Commit

Permalink
fix: Alair did not work in Jupyter Lab because requirejs was not loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Sep 13, 2023
1 parent 0260b08 commit a8253db
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions solara/widgets/vue/vegalite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 + "/";
Expand Down

0 comments on commit a8253db

Please sign in to comment.