-
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: Alair did not work in Jupyter Lab because requirejs was not loaded.
- Loading branch information
1 parent
0260b08
commit a2b28a3
Showing
1 changed file
with
31 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,21 +6,24 @@ | |
<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`, | ||
(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 | ||
require(['vega', 'vega-lite', 'vega-embed'], () => { | ||
}) | ||
}) | ||
// pre load | ||
require(['vega', 'vega-lite', 'vega-embed'], () => { | ||
}) | ||
})(); | ||
this.do_plot_debounced = _.debounce(() => this.do_plot(), 100) | ||
}, | ||
mounted() { | ||
|
@@ -64,6 +67,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 + "/"; | ||
|