PumasAI / QuartoNotebookRunner.jl

MIT License
61 stars 8 forks source link

Pluto integration #125

Open fonsp opened 4 months ago

fonsp commented 4 months ago

Hi! It would be great if Pluto notebooks could work as an input format for Quarto! I talked briefly about this with @MichaelHatherly and with the Quarto devs at JupyterCon last year :) I believe that quite a nice integration is possible!

This issue could be used to collect ideas on what the integration would look like, and to find out whether there is interest in this feature.

co1emi11er2 commented 4 months ago

Yes this would be an awesome integration! As someone who sees the potential use for this in my area of industry, let me know if I can help in any way.

MichaelHatherly commented 4 months ago

Hi! It would be great if Pluto notebooks could work as an input format for Quarto!

What do you have in mind with this integration? This backend just takes .qmds (or quarto's script format, https://quarto.org/docs/computations/render-scripts.html) and runs them. By integration are you meaning

quarto render path/to/pluto/notebook.jl

and have that "just work" for .jl files produced by Pluto?

co1emi11er2 commented 4 months ago

I can take a shot at an idea. I don't know how Pluto, QuartoNotebookRunner (lets abreviate this to QNR), or Quarto work under the hood, so this could be completely wrong.

First question would be: If I had a pluto notebook that I kept linear in terms of cell order and stuck to the quarto script format, would this be rendered correctly already with QNR?

Idea

This is under the assumption that quarto passes the whole script to QNR and QNR does the parsing of the file. If quarto passes the cell chunks to QNR to then run, then this idea breaks down.

My idea would be:

1. Tell QNR that it is a pluto notebook.

It could be QNR determining that on its own by looking for the ### A Pluto.jl notebook ### or # ╔═╡ type symbols in the file. Or something in the yaml header block.

2. QNR would then let Pluto or PlutoDependencyExplorer to parse the file.

Hopefully we can keep the comments within the cell blocks to keep quarto commands so we can adjust outputs. I know macros parse comments out so it may have to be parsed back in afterwards depending on how pluto works.

By parsing the file I imagine having a list of code, output that is sorted not by the linear order needed to run the code, but by the order specified by how you see it rendered in the pluto document. I imagine that tooling is already there within pluto.

3. Parsed input/outputs passed to quarto to render

Now with this list quarto can then take that information to build the pdf/html/etc.

MichaelHatherly commented 4 months ago

This is under the assumption that quarto passes the whole script to QNR and QNR does the parsing of the file.

That is correct, quarto (the binary) passes the file contents as a whole to our backend, which then sends the cells to worker processes for evaluation.

The main question we need to address is still https://github.com/PumasAI/QuartoNotebookRunner.jl/issues/125#issuecomment-2098650720, what do you expect from the high-level user-interface for this? Just run quarto render directly on a Pluto notebook @co1emi11er2? Let's not worry about all the internal workings of everything just yet.

co1emi11er2 commented 4 months ago

I guess the overall goal for me is to make it even more high level (no CLI). I want just an export or preview button inside pluto sort of like vscode extension where you can see the preview and saving the file will auto-render it again. But I would be fine with quarto render as the starting point for sure.

Most of the people I hope to convince to use pluto do not know the terminal, julia, quarto, or python. Our main tool for calculations is excel, so the more things I can pull away from a CLI, the better.

MichaelHatherly commented 4 months ago

Thanks. If this is just about getting nice Quarto renders of Pluto notebooks (which would be great) then the most straightforward way would be a feature directly in Pluto that uses quarto_jll.jl to shell out to quarto render and provides it as input a fully executed markdown/ipynb file that quarto already understands how to render.

That's pretty much what this package does internally anyway. We generate JSON output for executed .qmd in .ipynb format that quarto render already knew how to render.

MichaelHatherly commented 4 months ago

It would be great if Pluto notebooks could work as an input format for Quarto!

This one is a different request. Doing something like that requires first making quarto understand Pluto's notebook format. That is not actionable in this package. It'll need upstream changes.

robot144 commented 2 months ago

For my work teaching, it would be great if topic explanations written as pluto files could be integrated into a website generated with quarto. The pluto files will then contain interactivity which will be rendered to html, so that the explanations can be read and figures seen. For interactivity, or even playing with the code, it would be great to have a link to the pluto file that can be pasted into a running pluto instance. Or even a link that opens the file in binder for example.