fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.94k stars 285 forks source link

Delay running the notebook when it starts #259

Closed ndgnuh closed 10 months ago

ndgnuh commented 4 years ago

Hi, thanks for the super awesome package. This is just some suggestion. Sometime I want to edit something before running all the cell, and there will be a very time-taking cell at the end. But stopping after the cell run is not very responsive and might kill the worker. I know I can edit the jl file before running Pluto but it's not very convenient. Also, with delayed run, a run all (*, above, below) button would be nice. :)

fonsp commented 4 years ago

I wrote a bit about it here - it is also a good idea to do this by default for notebooks that were written by someone else.

j-fu commented 4 years ago

In a similar spirit I would like to have this option for running cells one-by one after loading when teaching based on a-priori prepared notebooks. Another thing nice to have in this context would be the option to hide all source code of markdown cells at once. Together this would provide an experience similar to that of Jupyter when loading a fresh notebook.

fonsp commented 4 years ago

About automatically hiding markdown: I don't this is necessary when you write your notebooks inside Pluto, but in your case (https://github.com/fonsp/Pluto.jl/issues/132#issuecomment-675764316), it can be done as part of the export process (the fold info is stored in the file):

c = Pluto.Cell("123")
c.folded = true
# save the notebook

Running cells one by one used to be the default (before https://github.com/fonsp/Pluto.jl/commit/d2015176af6ef437ad4feafedf1a01dae05426c9), but there were too many problems with this that we could not fix with friendly UI - the issue is that you launch your notebook into a broken state by default - running a cell might error depending on which cells you manually ran before. It had a lot of the same state problems as Jupyter that reactivity should solve. (The goal is not to make 'Jupyter++', but to try something else.)

But if you just want the 'reveal' effect, then you can add a ; at the end, and delete it and re-run when you want the output to show.

j-fu commented 4 years ago

About automatically hiding markdown: I don't this is necessary when you write your notebooks inside Pluto, but in your case (#132 (comment)), it can be done as part of the export process (the fold info is stored in the file):


c = Pluto.Cell("123")
c.folded = true
# save the notebook
This looks good - it seems that it would be easy to set this for all markdown cells bevore saving, at least as an option.

Running cells one by one used to be the default (before [d201517](https://github.com/fonsp/Pluto.jl/commit/d2015176af6ef437ad4feafedf1a01dae05426c9)), but there were too many problems with this that we could not fix with friendly UI - the issue is that you launch your notebook into a broken state by default - running a cell might error depending on which cells you manually ran before. It had a lot of the same state problems as Jupyter that reactivity should solve. (The goal is not to make 'Jupyter++', but to try something else.)

But if you just want the 'reveal' effect, then you can add a `;` at the end, and delete it and re-run when you want the output to show.

This feels a bit awkward to me, in particular when I want to do timing examples etc. With Jupyter, I always intended to start with an empty notebook. I could guarantee that cells are in linear order and that execution is done in this order. In the spirit of c.folded, I very much would prefer to have a flag like c.execute_on_load which I could set to false.

It depends of course how much work it would be for you. I don't see much need to have a friendly UI way to fix a messed up cell order, responsibility could be loaded off to the creator of the notebook.

fonsp commented 4 years ago

Hm, you could try using Pluto.run(run_notebook_on_load=false), but it's not really within the scope of this project to recreate the jupyter runtime. The flag is only there for some tricky test cases.

j-fu commented 4 years ago

Ok but with this, once I run the first cell, all dependants are triggered. I tried out

       foldedcells=Array{Cell,1}(undef,0)
        for cell in nb.cells
            if cell.code_folded
                push!(foldedcells,cell)
            end
        end
        println("run folded cells")
        update_save_run!(session, nb, foldedcells; run_async=true, prerender_text=true)

which gives a pretty nice initial state showing the results of folded markdown cells (I created the notebook this way). When I run the first non-folded cell, all dependants are triggered, though.

Having a possibility to run the non-folded code cells one-by-one assuming linear order would be really nice for teaching based on a-priori prepared scripts (sorry for insisting...) Perhaps another state flag could help here: optionally allow code cells to be blocked from execution after loading. Unblocking via GUI (e.g. by pressing the execute button) then is akin to adding a new cell and executing it, while all dependants still are kept blocked from execution.

DhruvaSambrani commented 3 years ago

Apart from the inconvenient side effects, this also has the security problem of running malicious code without the user being able to prevent it.

fonsp commented 3 years ago

That's right - https://www.notion.so/Notebook-security-d8162867a8c04b1793912d78cefee02a

pbouffard commented 3 years ago

Just came here to mention another use case for the delayed-execution-open: Opening a notebook for the sole purpose of copying some cells for pasting into another notebook.

cocoa1231 commented 3 years ago

Hello

I just wanted to ask if there was any update regarding this issue? Is it planned to be implemented? Thanks!

BioTurboNick commented 3 years ago

I wanted to +1 this. I have a notebook I created that does a lot and exports some data. I want to use it as a template for a new notebook with some modifications.

Pluto allows a notebook to be executed without being opened; why not opened without being executed?

A big button could be put up top that allows it to start executing, and then it can behave like normal.

Especially because running it on Windows doesn't allow you to interrupt execution.

ndgnuh commented 3 years ago

Just an idea on related problem, if we can have a cell delay widget for PlutoUI, it would be awesome. For very heavy computed cells that relies on many inputs, the delay widget would act like a submit button and run the cell only when pressed. RIght now I'm doing this by having a PlutoUI.Checker() to guard the computation, I uncheck it when I don't want it to run. This works but not every convenience.

Masacroso commented 2 years ago

I would like this option too. Some computations are very lengthy and its very annoying that the notebook run automatically from the start. I would like to prevent it, so I can make some change to the notebook before it run.

pnadon commented 2 years ago

I would like this option too. Some computations are very lengthy and its very annoying that the notebook run automatically from the start. I would like to prevent it, so I can make some change to the notebook before it run.

This is the same issue I have, it would be nice if I could flag certain cells as being manual, without having to comment them out / remove a function call

lungben commented 2 years ago

1895 should help here

fonsp commented 1 year ago

This should also apply to executing JS in HTML outputs.

fonsp commented 1 year ago

Even with a prompt, it would be really easy to hide malicious code in a normal-looking notebook, when sharing the notebook via a URL. Some (extreme) ideas:

Source

We could show the URL, and ask the user: "was this link sent to you by someone you trust?"

For a GitHub URL, get the username and ask if we trust this user.

Content

We could force users to review the code by showing each cell's code in sequence. (You have to click yes, yes, yes.) We can filter out cells that are empty or just markdown/html. This is quite tedious, so we could allow skipping this if the user trusts the author and source.

Good alternative

During review, we could already propose a safe alternative: run this notebook using binder or JuliaHub. This would make it less likely that people skip proper review because they really want to run a cool notebook.

fonsp commented 10 months ago

Implemented in Pluto 0.19.30! Check out the PR #2563 for more details!