-
Hello I recently updated to the newest version of perspective and I'm glad to see the new "export" functionality being accessible from widget following this PR #2418 :) However, I am interested in using the export > to html functionality from the python API (something like widget.to_html("file.html") Does this functionality exists today ? I'm not finding it in the docs Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
texodus
Feb 7, 2024
Replies: 1 comment 1 reply
-
We have plans to add this, in the meantime this logic is easy to replicate ad-hoc, it is just a simple string template - in Python it would look something like this: def to_html(view, version="2.7.1", layout="{}"):
import base64
arrow = view.to_arrow()
html = """
<!DOCTYPE html lang=\"en\">
<html>
<head>
<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no\"/>
<link rel=\"stylesheet\" crossorigin=\"anonymous\" href=\"https://cdn.jsdelivr.net/npm/@finos/perspective-viewer@{0}/dist/css/themes.css\"/>
<script type=\"module\">
import perspective from \"https://cdn.jsdelivr.net/npm/@finos/perspective@{0}/dist/cdn/perspective.js\";
import \"https://cdn.jsdelivr.net/npm/@finos/perspective-viewer@{0}/dist/cdn/perspective-viewer.js\";
import \"https://cdn.jsdelivr.net/npm/@finos/perspective-viewer-datagrid@{0}/dist/cdn/perspective-viewer-datagrid.js\";
import \"https://cdn.jsdelivr.net/npm/@finos/perspective-viewer-d3fc@{0}/dist/cdn/perspective-viewer-d3ffc.js\";
import \"https://cdn.jsdelivr.net/npm/@finos/perspective-viewer-openlayers@{0}/dist/cdn/perspective-viewer-openlayers.js\";
const worker = perspective.worker();
const binary_string = window.atob(window.data.textContent);
const len = binary_string.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {{
bytes[i] = binary_string.charCodeAt(i);
}}
window.viewer.load(worker.table(bytes.buffer));
window.viewer.restore(JSON.parse(window.layout.textContent));
</script>
<style>perspective-viewer{{position:absolute;top:0;left:0;right:0;bottom:0}}</style>
</head>
<body>
<script id='data' type=\"application/octet-stream\">{1}</script>
<script id='layout' type=\"application/json\">{2}</script>
<perspective-viewer id='viewer'></perspective-viewer>
</body>
</html>
""".format(version, base64.b64encode(arrow), layout)
return html |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ccarli
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have plans to add this, in the meantime this logic is easy to replicate ad-hoc, it is just a simple string template - in Python it would look something like this: