tom
tom

Reputation: 171

Running Jupyter notebook (and generating plots) from the command line

I'm trying to use the terminal to run a jupyter notebook (kernel: Julia v1.6.2), which contains generated using Plots.jl, before uploading the notebook to github for viewing on nbviewer.com.

Following this question:

How to run an .ipynb Jupyter Notebook from terminal?

I have been using nbconvert as follows:

jupyter nbconvert --execute --to notebook --inplace

This runs the notebook (if you tweak the timeout limits), however, it does not display plots when using Plots.jl, even when I explicitly call display(plot()) at the end of a cell.

Does anyone have any idea how notebooks can be run remotely in such a manner that plots will be generated and displayed, particularly when using Julia?

Upvotes: 3

Views: 851

Answers (2)

Phillip
Phillip

Reputation: 1

Launch notebook with using IJulia and notebook() in the REPL

Upvotes: 0

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42244

I managed to generate Plots.jl plots by getting from IJulia the same configuration it uses to run notebooks (this is probably the most sure way when you have many Pyhtons etc.).

using Conda, IJulia
Conda.add("nbconvert") # I made sure nbconvert is installed

mycmd = IJulia.find_jupyter_subcommand("nbconvert")
append!(mycmd.exec, ["--ExecutePreprocessor.timeout=600","--to", "notebook" ,"--execute", "note1.ipynb"])

Now mycmd has exactly the same environment as seen by IJulia so we can do run(mycmd):

julia> run(mycmd)
[NbConvertApp] Converting notebook note1.ipynb to notebook
Starting kernel event loops.
[NbConvertApp] Writing 23722 bytes to note1.nbconvert.ipynb

The outcome got saved to note1.nbconvert.ipynb, I open it with nteract to show that graphs actually got generated:

enter image description here

Upvotes: 3

Related Questions