-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
How would I capture PlotlyJS.jl figures as HTML? #126
Comments
Does Documenter handle this? In that case, perhaps try with Currently, markdown execution only handles Line 481 in 5db8c22
|
Ok so this is a feature request (for the whole package chain)? |
Probably, but I thought it worked in Documenter already, but maybe I misremember. I think JuliaDocs/Documenter.jl#1247 is causing some trouble for including the necessary js library. |
Thanks for the link! I thought PloylyJS's docs used HTML plots a while back, but it appears they're PNG now. Perhaps this is related. |
Maybe Literate could produce a raw block for documenter? |
So my hack is to add commented raw html and use your post processing |
Okay, using import Plots
struct HTMLPlot
p # :: Plots.Plot
end
const ROOT_DIR = joinpath(@__DIR__, "build")
const PLOT_DIR = joinpath(ROOT_DIR, "plots")
function Base.show(io::IO, ::MIME"text/html", p::HTMLPlot)
mkpath(PLOT_DIR)
path = joinpath(PLOT_DIR, string(hash(p) % UInt32, ".html"))
Plots.savefig(p.p, path)
print(io, "<object type=\"text/html\" data=\"../$(relpath(path, ROOT_DIR))\" style=\"width:100%;height:600px;\"></object>")
end you can just return
|
I thought the point of using Literate was that the .jl scripts for, e.g. a repository's examples, are still standalone. Wouldn't Perhaps a more seamless solution would be if Also, in the object type, the height seems to make an appreciable difference (I switched back to default size with height 400px for better mobile support), since it's a fixed pixel size. Given a plot |
Thanks @fredrikekre! Works like a charm! Just FYI, when using prettyurl in the CI framework, I had to make the following modification: function Base.show(io::IO, ::MIME"text/html", p::HTMLPlot)
mkpath(PLOT_DIR)
path = joinpath(PLOT_DIR, string(hash(p) % UInt32, ".html"))
Plots.savefig(p.p, path)
if get(ENV, "CI", "false") == "true" # for prettyurl
print(io, "<object type=\"text/html\" data=\"../../$(relpath(path, ROOT_DIR))\" style=\"width:100%;height:425px;\"></object>")
else
print(io, "<object type=\"text/html\" data=\"../$(relpath(path, ROOT_DIR))\" style=\"width:100%;height:425px;\"></object>")
end
end |
I have another question regarding PlotlyJS though. Does anyone have an idea how to get them working in Jupyter notebooks? On my own computer I got them to work with this extension, i.e. by executing this command
But I am puzzled how to incorporate that in the make.jl or somewhere so that a) the precomputed notebooks (executed by the GitHub action) display the figures and b) binder knows how to handle these plots. Neither is working right now. @fredrikekre, do you have yet another trick up your sleeve? Thank a ton for your help in advance! |
No idea, sorry. |
I'm currently setup to convert a .jl script to markdown using
Literate.markdown
for inclusion as generated pages in Documenter. But the captured output gives the figures a random number name and thus Plots.jl defaults to saving the figure as a PNG instead of HTML. Is this avoidable?My basic script is here https://github.com/JuliaApproximation/FastTransforms.jl/blob/master/examples/disk.jl
The docs build is here https://github.com/JuliaApproximation/FastTransforms.jl/blob/master/docs/make.jl
The text was updated successfully, but these errors were encountered: