-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PerspectiveWidget HTML export support in Jupyter
Add `text/html` output to PerspectiveWidget's `_repr_mimebundle_` method, which is read by nbconvert when exporting a notebook to HTML.
- Loading branch information
1 parent
785b1ee
commit 4198f1f
Showing
5 changed files
with
75 additions
and
1 deletion.
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
41 changes: 41 additions & 0 deletions
41
python/perspective/perspective/templates/exported_widget.html.jinja
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,41 @@ | ||
<script type="module" | ||
src="https://cdn.jsdelivr.net/npm/@finos/perspective@{{psp_version}}/dist/cdn/perspective.js"></script> | ||
<script type="module" | ||
src="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer@{{psp_version}}/dist/cdn/perspective-viewer.js"></script> | ||
<script type="module" | ||
src="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer@{{psp_version}}-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script> | ||
<script type="module" | ||
src="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer-d3fc@{{psp_version}}/dist/cdn/perspective-viewer-d3fc.js"></script> | ||
|
||
<link rel="stylesheet" crossorigin="anonymous" | ||
href="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer@{{psp_version}}/dist/css/pro.css" /> | ||
|
||
<div class="perspective-envelope" id="perspective-envelope-{{viewer_id}}"> | ||
<script type="application/vnd.apache.arrow.file"> | ||
{{ b64_data }} | ||
</script> | ||
<perspective-viewer style="height: 690px;"></perspective-viewer> | ||
<script type="module"> | ||
// from MDN | ||
function base64ToBytes(base64) { | ||
const binString = atob(base64); | ||
return Uint8Array.from(binString, (m) => m.codePointAt(0)); | ||
} | ||
import * as perspective from "https://cdn.jsdelivr.net/npm/@finos/perspective@{{psp_version}}/dist/cdn/perspective.js"; | ||
const viewerId = {{ viewer_id | tojson }}; | ||
const currentScript = document.scripts[document.scripts.length - 1]; | ||
const envelope = document.getElementById(`perspective-envelope-${viewerId}`); | ||
const dataScript = envelope.querySelector('script[type="application/vnd.apache.arrow.file"]');; | ||
if (!dataScript) | ||
throw new Error('data script missing for viewer', viewerId); | ||
const data = base64ToBytes(dataScript.textContent); | ||
const viewerAttrs = {{ viewer_attrs | tojson }}; | ||
// Create a new worker, then a new table promise on that worker. | ||
const table = await perspective.worker().table(data.buffer); | ||
const viewer = envelope.querySelector('perspective-viewer'); | ||
viewer.load(table); | ||
viewer.restore(viewerAttrs); | ||
</script> | ||
</div> |
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