-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Static preview, live Binder in the background #811
Conversation
@Ellipse0934 @mbauman I merged this and #988 into Pluto and released as 0.14.1! Normal users won't see the effects, but it means that 'vanilla' Pluto now has this functionality built in. I also updated the popup box in the top right from a single binder button (like in the demo video of this PR) to the two-click button we used on https://computationalthinking.mit.edu/. This should make it easier to edit and add options like the juliahub button! |
Pointer how to actually generate an HTML file programmatically as in #899? |
@OvidiusCicero You mean something like import Pluto
s = Pluto.ServerSession();
nb = Pluto.SessionActions.open(s, "./notebook.jl"; run_async=false)
html_contents = Pluto.generate_html(nb)
write("./notebook.html", html_contents) ? |
exactly thank you! Is there a way to spawn this from a running Pluto session, maybe without the time intensive line
? |
You can use the export button in the top right |
@OvidiusCicero Maybe you want to use |
@fonsp I want to trigger the export button programmatically @Ellipse0934 i guess that works |
You can also right click the export button to get the link and do some hacking with the |
@fonsp this looks like an approachable idea but |
Ah oops, that is the cell id. Sorry! If you can convince me why this feature would be useful I can think about it more :) |
Co-authored-by: Fons van der Plas <[email protected]> Co-authored-by: Michiel Dral <[email protected]> Co-authored-by: Παναγιώτης Γεωργακόπουλος <[email protected]>
@fonsp thanks, sorry I was distracted the last weeks I can indeed get the ID of the notebook by
when I open the link in the browser I seemingly get the HTML
I use the generated static HTML pages (okay, they're not so much static) from Pluto as reports to present results (like sending them around) and features like this would make keeping the HTML in sync with the actual notebook much easier |
Ah that's because the Pluto server is behind authentication. (You could disable authentication.) Another idea is to fork Pluto and implement this directly. You could look for the places where we call |
how are the authentications turned off? I found This and other stuff like I'll also look into forking Pluto for this some time, this seems to be the cleanest way, but it will take time |
@OvidiusCicero It would be great if you could figure out a way to get those things into the docstring for |
To fully disable authentication you need to disable both flags: Lines 28 to 52 in 099f40a
|
A minimal demo of a static notebook transitioning to a live binder session
You can already run Pluto notebooks on binder, but the load times are too long without anything too look at. You would not use this to write interactive articles on the web. So we're still not revolutionizing scientific publishing! Oops!
The solution:
Demo link:
https://pluto-binder-static-to-live-1.netlify.app/editor.html?notebookfile=https%3A%2F%2Fmkhj.fra1.cdn.digitaloceanspaces.com%2Fsample%2520Tower%2520of%2520Hanoi%252016.jl&statefile=https%3A%2F%2Fmkhj.fra1.cdn.digitaloceanspaces.com%2Fsample%2520Tower%2520of%2520Hanoi%252016.jl.plutostate&binder_url=https%3A%2F%2Fmybinder.org%2Fbuild%2Fgh%2Ffonsp%2Fpluto-on-binder%2Fstatic-to-live-1
Schermopname.2020-12-22.om.23.54.44.mov
How it works
We host the Pluto editor online on a CDN (i.e. we just host the
/frontend
folder):https://jovial-newton-a0c386.netlify.app/
with the editor at:
https://jovial-newton-a0c386.netlify.app/editor.html
We host with a snapshot of the (React) state of the notebook:
https://mkhj.fra1.cdn.digitaloceanspaces.com/sample%20Tower%20of%20Hanoi%2016.jl.plutostate
and the notebook file itself:
https://mkhj.fra1.cdn.digitaloceanspaces.com/sample%20Tower%20of%20Hanoi%2016.jl
These two URLs are passed to the editor as URL parameters. When the editor launhces with these url parameters, it downloads the state object and applies it locally, and displays a binder button.
A Binder session can be requested headless (in the background) using a special endpoint,
/build
instead of/v2
. This is used by https://github.com/executablebooks/thebeCode
The important edits are on the Pluto side (this PR), with matching changes to our binder'ed repository:
fonsp/pluto-on-binder#8
Description of changes
Code to request a binder in the background, based on https://github.com/executablebooks/thebe
Some changes to allow an export script to generate a version of
editor.html
with CDNified resources (http://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend/editor.css
instead of./editor.css
) and a baked base64-encoded state object.href="./
urls for easy string detection; HTML comment where JS can be insertedwindow.pluto_someproperty
or a&someproperty=
url parameterCSS changes:
body
and by changing themedia
attribute of thehide-ui.css
import fromprint
toall
Some changes to allow the Pluto server to run fully on CORS requests if security is disabled:
POST /open
endpoint to get the created notebook ID as a response, instead of a redirect to/edit?id=<new id>
, since redirects don't CORS nicely