JunoLab / Weave.jl

Scientific reports/literate programming for Julia
http://weavejl.mpastell.com
MIT License
830 stars 96 forks source link

Can't display Gadfly images #167

Open clintonTE opened 5 years ago

clintonTE commented 5 years ago

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 commented 5 years ago

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

clintonTE commented 5 years ago

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)
mpastell commented 5 years ago

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

clintonTE commented 5 years ago

Thank you! That's great news.

tlnagy commented 5 years ago

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 <notifications@github.com 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 .

clintonTE commented 5 years ago

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")
tlnagy commented 5 years ago

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?

mpastell commented 5 years ago

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 commented 5 years ago

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.

clintonTE commented 5 years ago

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.

Figuera commented 5 years ago

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

pfitzseb commented 5 years ago

Can you paste a MWE here?

Figuera commented 5 years ago

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

hw2.jmd:

```julia; echo = false
using Gadfly

TEXT

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:
plot(y = rand(100))


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

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