Skip to content

Commit

Permalink
fix: make altair and vega work in colab
Browse files Browse the repository at this point in the history
This might break classic notebook where requirejs is already available.
Proof of concept fix
  • Loading branch information
maartenbreddels committed Sep 29, 2023
1 parent 115d423 commit 1a16262
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions solara/widgets/vue/vegalite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ module.exports = {
});
},
async loadVega() {
// we need to remove the define function to avoid conflicts with requirejs
// which will do an early exit:
// https://github.com/requirejs/requirejs/blob/898ff9e60eb6897500720151c0b488b8749fbe8d/require.js#L177
// the define function is added by on colab when widgets are loaded:
// https://github.com/googlecolab/colab-cdn-widget-manager/blob/664b13da3289597966bfb5b7dd5e347233d48524/src/amd.ts#L81
const previousDefine = window.define;
delete window.define;
await this.loadRequire();
requirejs.undef("vega")
requirejs.undef("vega-lite")
Expand All @@ -70,6 +77,8 @@ module.exports = {
// pre load
await new Promise((resolve, reject) => {
require(['vega', 'vega-lite', 'vega-embed'], () => {
// should we restore the define function?
window.define = previousDefine;
resolve()
}, reject)
});
Expand Down

0 comments on commit 1a16262

Please sign in to comment.