-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export Jupyterlab notebook into HTML #1393
Comments
Plotly embeds all the information necessary to reconstruct the visualization, whereas currently for perspective we do not. In default mode, all the data is only on the Python side so its not feasible to reconstruct completely (though @texodus might disagree and have thoughts or a strategy on how to do this, e.g. by shipping all the data to the client in some form or another), though in |
maybe @vidartf has some thoughts and can help implement this for perspective ;-) |
This is very doable, but comes with a specific caveat: there is no easy way to get just a picture or otherwise stripped-down version of a That being said, perspective excels (np) at data serialization, it should be trivial to dump the entire It is possible to implement full serialization (for PDFs, e-mails, GitHub, etc) now that we've ported to |
Thank you both @texodus and @timkpaine. I have been discussing some use-cases with other team members for HTML exports:
I do not think that it is necessary to implement full serialization e.g. to PDF, since the be the best feature of Perspective is interactivity and people can use some other plotting library for this purpose (e.g. Plotly) or make a printscreen of the current state and paste it to notebook :). I think that for case 1) it definitely makes sense to include the entire Honestly, I do not fully understand what you mean by including <div id="altair-viz-033ce8343a904cba8ef37fea260ac22e"></div>
<script type="text/javascript">
(function(spec, embedOpt){
let outputDiv = document.currentScript.previousElementSibling;
if (outputDiv.id !== "altair-viz-033ce8343a904cba8ef37fea260ac22e") {
outputDiv = document.getElementById("altair-viz-033ce8343a904cba8ef37fea260ac22e");
}
const paths = {
"vega": "https://cdn.jsdelivr.net/npm//vega@5?noext",
"vega-lib": "https://cdn.jsdelivr.net/npm//vega-lib?noext",
"vega-lite": "https://cdn.jsdelivr.net/npm//[email protected]?noext",
"vega-embed": "https://cdn.jsdelivr.net/npm//vega-embed@6?noext",
};
function loadScript(lib) {
return new Promise(function(resolve, reject) {
var s = document.createElement('script');
s.src = paths[lib];
s.async = true;
s.onload = () => resolve(paths[lib]);
s.onerror = () => reject(`Error loading script: ${paths[lib]}`);
document.getElementsByTagName("head")[0].appendChild(s);
});
}
function showError(err) {
outputDiv.innerHTML = `<div class="error" style="color:red;">${err}</div>`;
throw err;
}
function displayChart(vegaEmbed) {
vegaEmbed(outputDiv, spec, embedOpt)
.catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));
}
if(typeof define === "function" && define.amd) {
requirejs.config({paths});
require(["vega-embed"], displayChart, err => showError(`Error loading script: ${err.message}`));
} else if (typeof vegaEmbed === "function") {
displayChart(vegaEmbed);
} else {
loadScript("vega")
.then(() => loadScript("vega-lite"))
.then(() => loadScript("vega-embed"))
.catch(showError)
.then(() => displayChart(vegaEmbed));
}
})({"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}}, "data": {"url": "https://cdn.jsdelivr.net/npm/[email protected]/data/us-10m.json", "format": {"feature": "counties", "type": "topojson"}}, "mark": "geoshape", "encoding": {"color": {"type": "quantitative", "field": "rate"}}, "height": "container", "projection": {"type": "albersUsa"}, "transform": [{"lookup": "id", "from": {"data": {"url": "https://cdn.jsdelivr.net/npm/[email protected]/data/unemployment.tsv"}, "key": "id", "fields": ["rate"]}}], "width": "container", "$schema": "https://vega.github.io/schema/vega-lite/v4.8.1.json"}, {"actions": false, "mode": "vega-lite"});
</script> Think the first and easier step could be implementing |
Initial support for notebook HTML export landed in 2.7.0, with the caveats @texodus mentioned about ipynb file sizes #2418 To enable this either:
|
Support Question
Hi I have tried to export jupyter notebook into html with nbconvert. Unfortunately, it does not export the perspective visualization (e.g. like plotly). Do you have any idea how to make it work? I thought to make a custom nbconvert exporter and include perspective javascript, but all I can see in jupyter notebook is this:
The text was updated successfully, but these errors were encountered: