I’m trying to modify the Base.show function to show images in the plot pane of Atom/Juno following the instructions there. But nothing shows in my plot pane when I execute the commands (either directly from the atom REPL or by executing lines in a file opened with atom)
when running it, the plot pane stays empty (I’m showing the last line to show that the file exists). Not sure what I’m doing wrong? I also tried to copy paste the HTML example but same thing happened.
Thanks!
PS:
Julia Version 1.1.0-DEV.663
Commit 26f1ba56f9 (2018-11-15 22:17 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin14.5.0)
CPU: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = atom -a
JULIA_NUM_THREADS = 2
The read was successful by the looks, as you have some Uint8 data. I’d guess it wants base64 data and probably a header. There is a method hiding in Markdown somewhere, but this should also work
using Base64
bazstr = "data:image/png;base64," * base64encode(read(b.fn));
That solution isn’t really a good idea – I wouldn’t recommend overloading Juno.render anymore since you do basically everything with Base.show now. If you want to use Juno.render directly then it’d be best to overload it directly for your type instead of going through a show method.
I have no idea why the solution in your original post isn’t working though:
My two best guesses would be that either I changed something on Atom.jl master (or atom-julia-client master) that un-breaks this, or that your png is weird somehow.
I typed pretty much exactly what’s in your screencast (thanks for taking the time) and tried with several random png images found on google images with just the same result
Edit: did just that and no difference in output (even after fully restarting atom).
FWIW, I also tried the SVG example (copy pasting from the doc, with different svg files) and the HTML example, none showed in the plot pane. Could it be related to the fact that I’m on a Mac? Can anyone else reproduce this?
thanks, that’s my exact setup, I also tried with both 1.0 and 1.1, up to date Juno, Atom & all packages in the main Atom app. No idea what’s going on then.
No, the show function for image/png should not be producing base64 data, it should be producing raw binary data. (If the display backend needs base64 encoding, it needs to do that itself with the data provided by show.)
Your original Base.show(io::IO, ::MIME"image/png", b::Baz) = write(io, read(b.fn)) code works just fine for me in IJulia. If it doesn’t work in Juno, then you should file a issue in Juno.
In particular, you should not be overloading Base.show(io::IO, b::Baz) to output HTML with embedded base64-encoded HTML. The 2-argument show function should produce plain text — otherwise, non-Juno displays (the REPL, for example), will be broken. If you want HTML output, you should overload show(io::IO, ::MIME"text/html", b::Baz).
that was it, thanks!! I wasn’t aware there was this setting. Would it make sense to maybe have a default where if the plot pane is opened this setting is set to true by default? thanks again!