Skip to content
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

Delay running the notebook when it starts #259

Closed
ndgnuh opened this issue Aug 6, 2020 · 18 comments · Fixed by #2563
Closed

Delay running the notebook when it starts #259

ndgnuh opened this issue Aug 6, 2020 · 18 comments · Fixed by #2563
Labels
frontend Concerning the HTML editor

Comments

@ndgnuh
Copy link

ndgnuh commented Aug 6, 2020

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
Copy link
Owner

fonsp commented Aug 6, 2020

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.

@fonsp fonsp added the frontend Concerning the HTML editor label Aug 6, 2020
@j-fu
Copy link
Contributor

j-fu commented Aug 18, 2020

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
Copy link
Owner

fonsp commented Aug 19, 2020

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

Running cells one by one used to be the default (before d201517), 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
Copy link
Contributor

j-fu commented Aug 19, 2020

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), 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
Copy link
Owner

fonsp commented Aug 19, 2020

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
Copy link
Contributor

j-fu commented Aug 20, 2020

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
Copy link
Contributor

DhruvaSambrani commented Sep 23, 2020

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
Copy link
Owner

fonsp commented Sep 23, 2020

@pbouffard
Copy link
Contributor

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.

@fonsp fonsp changed the title Delay running the cell when the notebook starts. Delay running the notebook when it starts Oct 20, 2020
@cocoa1231
Copy link

Hello

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

@pankgeorg pankgeorg mentioned this issue May 6, 2021
10 tasks
@BioTurboNick
Copy link
Contributor

BioTurboNick commented May 18, 2021

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
Copy link
Author

ndgnuh commented May 25, 2021

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
Copy link

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
Copy link

pnadon commented Nov 23, 2021

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
Copy link
Contributor

lungben commented Mar 15, 2022

#1895 should help here

@fonsp
Copy link
Owner

fonsp commented Jan 18, 2023

This should also apply to executing JS in HTML outputs.

@fonsp
Copy link
Owner

fonsp commented Jan 18, 2023

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 fonsp linked a pull request Oct 22, 2023 that will close this issue
30 tasks
@fonsp
Copy link
Owner

fonsp commented Oct 23, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Concerning the HTML editor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants