3

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?

tom
  • 171
  • 4
  • 1
    Just to be clear, the last line of the cell is `display(plot(x, y; options...))` (or however your plot call looks), not just an empty `display(plot())`, right? – Sundar R Jan 18 '22 at 23:55
  • Sorry, yes that's correct. – tom Jan 19 '22 at 01:54

2 Answers2

3

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

Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • Thanks! This almost works - I'm just getting the following error in the notebook, in place of a plot: No (safe) renderer could be found for output. It has the following MIME types: image/svg+xml. – tom Jan 21 '22 at 04:26
0

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