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

Fetching output of display #128

Closed
bkamins opened this issue Dec 3, 2020 · 6 comments
Closed

Fetching output of display #128

bkamins opened this issue Dec 3, 2020 · 6 comments

Comments

@bkamins
Copy link

bkamins commented Dec 3, 2020

I have the following question. I have a file:

function f()
    display([1 2; 3 4])
end

f()

called test.jl.

Now I run:

julia> Literate.markdown("test.jl", execute=true)
[ Info: generating markdown page from `D:\test.jl`
2×2 Array{Int64,2}:
 1  2
 3  4
[ Info: writing result to `D:\test.md`
"D:\\test.md"

julia> Literate.notebook("test.jl", execute=true)
[ Info: generating notebook from `D:\test.jl`
[ Info: executing notebook `test.ipynb`
2×2 Array{Int64,2}:
 1  2
 3  4
[ Info: writing result to `D:\test.ipynb`
"D:\\test.ipynb"

and display result is produced in the Julia session not in the markdown neither notebook. Is there a way to work around this? Thank you!

@bkamins bkamins changed the title Fetching output Fetching output of display Dec 3, 2020
@fredrikekre
Copy link
Owner

Sorry, didn't see this issue until now.

I am not sure how to catch display. I guess Literate would have to define a display and push that to the display stack: https://github.com/JuliaLang/julia/blob/c1c52930bb58605b60ae723c28f63e43b73944f6/base/multimedia.jl#L260

Why do you want to use display and not show though? I don't think I have ever called display myself, that is usually called by the REPL/IJulia backend.

@bkamins
Copy link
Author

bkamins commented Jan 19, 2021

In Jupyter Notebook you have to call display if you want HTML-formatted output produced in the middle of your computation, e.g. run the following code:

using DataFrames
foreach(display, [DataFrame(a=1), DataFrame(b=2)])

vs

using DataFrames
foreach(show, [DataFrame(a=1), DataFrame(b=2)])

@fredrikekre
Copy link
Owner

fredrikekre commented Jan 19, 2021

Thanks. I thought it would be as simple as this:

show(stdout, MIME"text/html"(), df)

but apparently not.

Edit: Nevermind, I am stupid.

@bkamins
Copy link
Author

bkamins commented Jan 19, 2021

This is the point stdout does not work in Jupyter Notebook AFAICT

fredrikekre added a commit that referenced this issue Jan 19, 2021
This implement a simple LiterateDisplay and pushes that
to the display stack when executing code to capture manual
calls to display(x) and display(mime, x), fixes #128.
@fredrikekre
Copy link
Owner

Works in 2.8.0 (JuliaRegistries/General#28270).

@bkamins
Copy link
Author

bkamins commented Jan 19, 2021

Thank you for looking into it. I have left a comment about how IJulia.jl works in your commit

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

No branches or pull requests

2 participants