-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate jupyter widgets manager extension
- Loading branch information
1 parent
f625a4d
commit 90a48e2
Showing
20 changed files
with
595 additions
and
187 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2018, Voilà contributors * | ||
* Copyright (c) 2018, QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
import { | ||
JupyterFrontEnd, | ||
JupyterFrontEndPlugin | ||
} from '@jupyterlab/application'; | ||
|
||
import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; | ||
|
||
import { Widget } from '@lumino/widgets'; | ||
|
||
/** | ||
* The plugin that renders outputs. | ||
*/ | ||
export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = { | ||
id: '@voila-dashboards/voila:render-outputs', | ||
autoStart: true, | ||
requires: [IRenderMimeRegistry], | ||
activate: (app: JupyterFrontEnd, rendermime: IRenderMimeRegistry): void => { | ||
// This "app.started.then" is a trick to make sure we render the output only when all plugins are loaded | ||
// Not using await here because we want this function to return immediately | ||
// Otherwise it prevents the application to start and resolve the "started" promise... | ||
app.started.then(() => { | ||
// Render outputs | ||
const cellOutputs = document.body.querySelectorAll( | ||
'script[type="application/vnd.voila.cell-output+json"]' | ||
); | ||
cellOutputs.forEach(async (cellOutput) => { | ||
const model = JSON.parse(cellOutput.innerHTML); | ||
|
||
const mimeType = rendermime.preferredMimeType(model.data, 'any'); | ||
|
||
if (!mimeType) { | ||
return null; | ||
} | ||
const output = rendermime.createRenderer(mimeType); | ||
output.renderModel(model).catch((error) => { | ||
// Manually append error message to output | ||
const pre = document.createElement('pre'); | ||
pre.textContent = `Javascript Error: ${error.message}`; | ||
output.node.appendChild(pre); | ||
|
||
// Remove mime-type-specific CSS classes | ||
pre.className = 'lm-Widget jp-RenderedText'; | ||
pre.setAttribute('data-mime-type', 'application/vnd.jupyter.stderr'); | ||
}); | ||
|
||
output.addClass('jp-OutputArea-output'); | ||
|
||
if (cellOutput.parentElement) { | ||
const container = cellOutput.parentElement; | ||
|
||
container.removeChild(cellOutput); | ||
|
||
// Attach output | ||
Widget.attach(output, container); | ||
} | ||
}); | ||
const node = document.getElementById('rendered_cells'); | ||
if (node) { | ||
const cells = new Widget({ node }); | ||
app.shell.add(cells, 'main'); | ||
} | ||
}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.