PumasAI / QuartoNotebookRunner.jl

MIT License
63 stars 10 forks source link

Plots from RCall are not shown #92

Closed felixcremer closed 7 months ago

felixcremer commented 7 months ago

When I have a julia code cell with an RCall string that plots something the output of that plot is hidden with QNR in contrast to the jupyter quarto run where the plot is shown. I would have expected that the corresponding plot is shown.

I attached an example qmd file which shows the behaviour. This is an actual quarto notebook I just had to rename it so that github would allow to upload it. rplot.md

MichaelHatherly commented 7 months ago

RCall does some IJulia-specific setup during init:

https://github.com/JuliaInterop/RCall.jl/blob/15178034400d449fb7500663717a9165c77ba020/src/setup.jl#L223-L224

It might be that we can just add that too the package hook code in the worker here https://github.com/PumasAI/QuartoNotebookRunner.jl/blob/f95ee95e27de27f5f33758d05cffe2ba499e015d/src/worker.jl#L687

@felixcremer are you able to see whether just manually calling that RCall.ijulia_init() function in the notebook in a cell prior to plotting anything causes it to start displaying plots?

felixcremer commented 7 months ago

I can't run this function because I get the following error even when I try to load IJulia also in the same notebook cell.

Running [1/1] at line 8:  using RCall
ERROR: Julia server returned error after receiving "run" command:
Failed to run notebook: /home/fcremer/Documents/NFDI4Earth/lhbarticles/rplot.qmd
ERROR: EvaluationError: Encountered 1 error during evaluation

Error 1 of 1
@ /home/fcremer/Documents/NFDI4Earth/lhbarticles/rplot.qmd:8
UndefVarError: `IJulia` not defined
Stacktrace:
 [1] getproperty
   @ ./Base.jl:31 [inlined]
 [2] ijulia_init()
   @ RCall ~/.julia/packages/RCall/YrsKg/src/ijulia.jl:92
 [3] top-level scope
   @ ~/Documents/NFDI4Earth/lhbarticles/rplot.qmd:11

ERROR: Internal julia server error

Stack trace:
    at writeJuliaCommand (file:///opt/quarto/bin/quarto.js:41572:19)
    at eventLoopTick (ext:core/01_core.js:153:7)
    at async executeJulia (file:///opt/quarto/bin/quarto.js:41481:22)
    at async Object.execute (file:///opt/quarto/bin/quarto.js:41261:20)
    at async renderExecute (file:///opt/quarto/bin/quarto.js:77765:27)
    at async renderFileInternal (file:///opt/quarto/bin/quarto.js:77933:43)
    at async renderFiles (file:///opt/quarto/bin/quarto.js:77801:17)
    at async render (file:///opt/quarto/bin/quarto.js:82629:21)
    at async renderForPreview (file:///opt/quarto/bin/quarto.js:83655:26)
    at async render (file:///opt/quarto/bin/quarto.js:83538:29)
felixcremer commented 7 months ago

I tried to run RCall.ijulia_displayplots() in the notebook cell but now I get the following error when I include the plot call into the cell.

ERROR: Julia server returned error after receiving "run" command:
Failed to run notebook: /home/fcremer/Documents/NFDI4Earth/lhbarticles/rplot.qmd
ERROR: EvaluationError: Encountered 1 error during evaluation

Error 1 of 1
@ /home/fcremer/Documents/NFDI4Earth/lhbarticles/rplot.qmd:8
REvalError: Error in modifyList(args, list(...)) : is.list(x) is not TRUE
Calls: plot ... dev.hold -> <Anonymous> -> do.call -> modifyList -> stopifnot
Stacktrace:
 [1] handle_eval_stderr(; as_warning::Bool)
   @ RCall ~/.julia/packages/RCall/YrsKg/src/io.jl:174
 [2] handle_eval_stderr
   @ ~/.julia/packages/RCall/YrsKg/src/io.jl:168 [inlined]
 [3] reval_p(expr::Ptr{LangSxp}, env::Ptr{EnvSxp})
   @ RCall ~/.julia/packages/RCall/YrsKg/src/eval.jl:103
 [4] reval_p(expr::Ptr{RCall.ExprSxp}, env::Ptr{EnvSxp})
   @ RCall ~/.julia/packages/RCall/YrsKg/src/eval.jl:119
 [5] reval(str::String, env::RObject{EnvSxp})
   @ RCall ~/.julia/packages/RCall/YrsKg/src/eval.jl:136
 [6] macro expansion
   @ ~/.julia/packages/RCall/YrsKg/src/macros.jl:71 [inlined]
 [7] top-level scope
   @ ~/Documents/NFDI4Earth/lhbarticles/rplot.qmd:11

ERROR: Internal julia server error

Stack trace:
    at writeJuliaCommand (file:///opt/quarto/bin/quarto.js:41572:19)
    at eventLoopTick (ext:core/01_core.js:153:7)
    at async executeJulia (file:///opt/quarto/bin/quarto.js:41481:22)
    at async Object.execute (file:///opt/quarto/bin/quarto.js:41261:20)
    at async renderExecute (file:///opt/quarto/bin/quarto.js:77765:27)
    at async renderFileInternal (file:///opt/quarto/bin/quarto.js:77933:43)
    at async renderFiles (file:///opt/quarto/bin/quarto.js:77801:17)
    at async render (file:///opt/quarto/bin/quarto.js:82629:21)
    at async renderForPreview (file:///opt/quarto/bin/quarto.js:83655:26)
    at async render (file:///opt/quarto/bin/quarto.js:83538:29)
MichaelHatherly commented 7 months ago

Thanks for checking, looks like we'll need to add some integration code to make it work correctly.