Any quick suggestions for existing packages or a workflow for including output of a Plot() in Julia html output written to a file??
Looking at a Weave or Literate+Documenter workflow as one option.
For reference, here is writeup of using BrowseTables.jl to export tabular data to an html file:
Would like to do something similar, but exporting a plot versus tabular data.
Ideally a one-liner that runs quickly (for interactive use).
You already mentioned Weave and Documenter. What do you need that they don’t provide?
If it’s brevity (you comment on “ideally a one-liner”), the burden required by Weave is not that much. You only need the jmd file with a chunk containing the code to do the plot, and run weave in one line (or one click if you use Juno). Same for IJulia. Or I am missing your point?
Besides, most plotting packages have a savefig or similar function to export the plot. Some accept html output, e.g. plotly(js) --which may be used as backend of Plots.jl—. And most accept svg output, which can be embedded in html as is.
Perhaps, just want to send a plot to index.html in current working directory.
Not sure how to do this with “embedding” (“…accept svg output, which can be embedded in html as is”.). Still working on a process that works for Weave/Documenter, so can’t answer your question quite yet.
Thank you, will try that this evening.
Thanks, trying this but not getting a file output? Looked at help for sprint but it’s not clear how to accomplish.
Tried to paste the full output, with and without the quotes, into an index.html file, but that doesn’t work (just blank output in browser save for "\n\n\n \n \n\n\n"
julia> open("index.html", "w") do io
show(io, "text/html", p)
end
show writes a representation of p to io and sprint basically calls the function with an IOBuffer and gives you a string back. So you could just copy (or write) the content of that string into a file, but the above is a bit simpler.
Thank you @pfitzseb!! This is working nicely for the plot. Requires no major dependencies and is quite straightforward. Let me play with a few other options and will mark this as solution if nothing simpler is found.
I know including the plot data itself wasn’t part of the requirement, but trying to do that and get it to look clean. BrowseTables.jl doesn’t seem to work within the loop ( HTMLTable(data) produces blank output).
Found a formatting solution in the Formatted printing of arrays thread:
Base.show(io::IO, f::Float64) = @printf io "%1.3f" f
and "%1.4f" for 4 sign digits, etc. Looking at DataFrames as well, as the show there can control scope of which rows/columns to output. Here is code and output at this point:
using Plots ; gr()
Base.show(io::IO, f::Float64) = @printf io "%1.3f" f
data = rand(14)
p=Plots.plot(1:14, data)
open("index.html", "w") do io
show(io, data)
show(io, "text/html", p)
end
using DataFrames
df=rand(11)
p=Plots.plot(1:11, df)
open("index.html", "w") do io
show(io, df)
show(io, "text/html", p)
end