Pluto to HTML without a browser
fonsp opened this issue Β· 10 comments
Not too difficult, just some Julia code that produces roughly the same HTML as the JS code (have a look at the .html export). You can use https://github.com/yurivish/Hyperscript.jl or just Markdown.withtag
to write it
It would be great if this export function also supported only exporting the main
part of the document, that would make it easy to include in a full HTML page with e.g. Franklin.jl.
Here is another potential use case for this feature:
Over at ParticleFilters.jl we would like to use Pluto as an "executable documentation" for our repo. Currently we are using Jupyter notbooks for this which has the benefit that users can view the notebook directly in the browser (of course only the static, non-interactive version) without the need to download or run anything.
Of course a 1-click deploy to project binder would solve this issue, however, for our use case it would be totally sufficient to just programmatically export the notebook to static HTML.
Ideally, I am envisioning to export the notebook to HTML automatically through the CI job that also builds the documentation (i.e. as part of docs/make.jl).
Why don't we do this with a headless chromium browser like the tests do?
(Sketching this up - be right back!!)
A solution can be the following script.
Steps:
- Open pluto without password (use startup.jl from binder template)
- Save url
- mkdir test_whatever
- npm i puppeteer
- save the below as 'export.js'
- node export.js http://localhost:1234/ /path/to/your/notebook /path/to/html/folder/you/want/it/saved/in/
Note argument 1 (pluto) url has trailing slash, argument 2 is your notebook, argument 3 is a folder
also requires your notebook to be ready in 5 seconds. I'll sketch something smarter up if it works for you
π π π π
const puppeteer = require('puppeteer');
const url = process.argv[2];
const file = process.argv[3];
const dir = process.argv[4];
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const client = await page.target().createCDPSession();
await client.send('Page.setDownloadBehavior', {
behavior: 'allow', downloadPath: dir || './'
});
const goto = `${url}open?path=${encodeURIComponent(file)}`;
await page.goto(goto);
console.log(goto)
await page.waitFor(5000);
await page.click('#at_the_top .toggle_export');
await page.waitFor(5000);
await page.click("aside#export a:nth-child(3)")
await browser.close();
})();
@lassepe does this work?
We'll build something equivalent to HTML export into pluto soonish
Would be great to have this in the next two weeks for use in a class that I am teaching in Julia! Also @mossr could probably benefit for his course materials: https://github.com/sisl/AA120Q
@fonsp I believe you had something like a Github Action to deploy Pluto notebooksοΌ
@VarLad github action for deploying Pluto notebooks would be awesome. Do you know if it's a thing now?
Check out https://github.com/JuliaPluto/static-export-template/ , which uses https://github.com/JuliaPluto/PlutoSliderServer.jl to generate HTML files without a browser :)