Weave.jl icon indicating copy to clipboard operation
Weave.jl copied to clipboard

Can't display Gadfly images

Open clintonTE opened this issue 5 years ago • 14 comments

I can't seem to get Gadfly graphs to render within the markdown document. I've tried passing the plot to outside the function, and several different ways to display. The image displays fine in atom\Juno and when I save it to a file.

julia> weave("JuliaSoln.md", informat="markdown", out_path=:pwd, doctype="md2html")
[ Info: Weaving chunk 1 from line 30
ERROR: MethodError: no method matching show(::Base.GenericIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("image/svg+xml")}, ::Array{UInt8,1})
Closest candidates are:
  show(::IO, ::MIME{Symbol("text/plain")}, ::AbstractArray) at arrayshow.jl:316
  show(::IO, ::MIME{Symbol("text/plain")}, ::Any) at sysimg.jl:194
  show(::IO, ::MIME{Symbol("text/csv")}, ::Any) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\DelimitedFiles\src\DelimitedFiles.jl:828
  ...
Stacktrace:
 [1] __binrepr(::MIME{Symbol("image/svg+xml")}, ::Array{UInt8,1}, ::Nothing) at .\multimedia.jl:127
 [2] _textrepr(::MIME{Symbol("image/svg+xml")}, ::Array{UInt8,1}, ::Nothing) at .\multimedia.jl:119
 [3] #stringmime#6(::Nothing, ::Function, ::MIME{Symbol("image/svg+xml")}, ::Array{UInt8,1}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Base64\src\Base64.jl:38
 [4] stringmime(::MIME{Symbol("image/svg+xml")}, ::Array{UInt8,1}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Base64\src\Base64.jl:38
 [5] img2base64(::String, ::String) at C:\Users\...\.julia\packages\Weave\1O5IK\src\run.jl:158
 [6] (::getfield(Weave, Symbol("##24#25")){String})(::String) at .\none:0
 [7] collect(::Base.Generator{Array{AbstractString,1},getfield(Weave, Symbol("##24#25")){String}}) at .\generator.jl:47
 [8] embed_figures(::Array{Weave.CodeChunk,1}, ::String) at C:\Users\...\.julia\packages\Weave\1O5IK\src\run.jl:144
 [9] run_chunk(::Weave.CodeChunk, ::Weave.Report, ::Module) at C:\Users\...\.julia\packages\Weave\1O5IK\src\run.jl:131
 [10] #run#21(::String, ::Symbol, ::Symbol, ::Dict{Any,Any}, ::String, ::Nothing, ::String, ::Symbol, ::Bool, ::typeof(run), ::Weave.WeaveDoc) at C:\Users\...\.julia\packages\Weave\1O5IK\src\run.jl:94
 [11] #run at .\none:0 [inlined]
 [12] #weave#10(::String, ::String, ::Symbol, ::Dict{Any,Any}, ::Symbol, ::String, ::Nothing, ::String, ::Symbol, ::Bool, ::Nothing, ::Nothing, ::Nothing, ::Array{String,1}, ::String, ::typeof(weave), ::String) at C:\Users\...\.julia\packages\Weave\1O5IK\src\Weave.jl:107
 [13] (::getfield(Weave, Symbol("#kw##weave")))(::NamedTuple{(:informat, :out_path, :doctype),Tuple{String,Symbol,String}}, ::typeof(weave), ::String) at .\none:0
 [14] top-level scope at none:0

clintonTE avatar Jan 27 '19 23:01 clintonTE

Nevermind, I see Gadfly doesn't work with this :(

clintonTE avatar Jan 27 '19 23:01 clintonTE

For posterity: As a work around, one can use the Images, FileIO, and ImageMagick (Windows) packages to open images saved by Gadfly as follows:

  draw(PNG("ExcessReturns.png",9inch, 7inch),p)
  im = load("ExcessReturns.png")
  display(im)

clintonTE avatar Jan 28 '19 00:01 clintonTE

@tlnagy is working on bringin Gadfly support back in: https://github.com/mpastell/Weave.jl/pull/163

mpastell avatar Jan 29 '19 06:01 mpastell

Thank you! That's great news.

clintonTE avatar Jan 29 '19 07:01 clintonTE

I think #163 is baked and ready to go, but I would appreciate some extra users to take it for a spin and make sure I didn't miss anything obvious. @ClintonTE could you checkout that PR and let me know how it behaves?

On Mon, Jan 28, 2019, 23:26 Clinton Tepper <[email protected] wrote:

Thank you! That's great news.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mpastell/Weave.jl/issues/167#issuecomment-458434783, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlaL8tSGa3fye5iQTmsD-M4OE-FXHDkks5vH_ekgaJpZM4aVAaH .

tlnagy avatar Jan 29 '19 17:01 tlnagy

Using the new PR- There is a new and rather bizarre issue. Starting from a new instance of Julia, the first time I run the code it opens the image (but not the rest of the html) in a new tab. Meanwhile the rendered html code does not include the image. When I run the code again, it generates the html correctly without the aberrant behavior. Restarting Julia then reproduces the issue.

If it helps the command I am running is:

weave("JuliaSoln.md", informat="markdown", out_path=:pwd, doctype="md2html")

clintonTE avatar Jan 30 '19 05:01 clintonTE

I haven't had time to reproduce this, but I vaguely remember this happening. I'm not sure why this would be happening. Do you have your using Gadfly statement and plot statement inside the same code block?

tlnagy avatar Feb 06 '19 19:02 tlnagy

I just tested this myself (Julia 1.1 on Windows 10) and the PR works for me without any errors. So I don't have the same problem that @clintonTE has.

mpastell avatar Feb 07 '19 17:02 mpastell

I have merged #163 after testing it on Linux as well (no problems for me on Ubuntu either). Thanks for the effort @tlnagy ! I will leave this issue open to track @clintonTE's problem. It would be could to know whether it's a problem with Weave or Gadfly.

mpastell avatar Feb 07 '19 17:02 mpastell

Cool, thanks @mpastell and @tlnagy! @tlnagy , the using Gadfly is in the same code block as plot. Also, the plot is wrapped in a function, if that affects anything.

clintonTE avatar Feb 07 '19 19:02 clintonTE

I am also being unable to display Gadfly images. It runs, it shows the plot but it does not put it on the html.

Figuera avatar Oct 26 '19 04:10 Figuera

Can you paste a MWE here?

pfitzseb avatar Oct 26 '19 09:10 pfitzseb

I don't know what you are meaning by a MWE but here is my "code":

hw2.jmd:

```julia; echo = false
using Gadfly
```

TEXT

```julia;
plot(y = rand(100))
```

I run on julia:

weave("hw2.jmd", out_path=:pwd)

The command run without errors, display me the plot as if I had just written the plot command on the julia REPL, but there is no image in the HTML.

This is the HTML code for where the plot should be:

<pre class='hljl'>
<span class='hljl-nf'>plot</span><span class='hljl-p'>(</span><span class='hljl-n'>y</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>(</span><span class='hljl-ni'>100</span><span class='hljl-p'>))</span>
</pre>

I don't have any experience using julia's Weave so it might as well be my fault. Am I missing something?

Figuera avatar Oct 26 '19 15:10 Figuera

Still same issue after 1 year. Gadfly version 1.3.1, Weave version 0.10.6, Julia version 1.5.2 on Win10.

humphreylee avatar Nov 17 '20 08:11 humphreylee