Embedding Plotly Graphs in HTML in Julia
How to embed plotly graphs in an iframe in HTML.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.
Saving An HTML in Julia
Plotly graphs can be embedd in any HTLM page. This includes Wordpress sites, dashboard, blogs and more.
To export a plot as html, use the PlotlyBase.to_html
method passing in an IO buffer and the plot
attribute of a generated plot:
using PlotlyJS
p = plot(scatter(x=[0,1,2], y=[3,6,2]))
open("./example.html", "w") do io
PlotlyBase.to_html(io, p.plot)
end Click to copy
nothing
Controlling the Size of the HTML file
To set the default height and width of the generated html, use default_height
and default_width
of the to_html
method:
using PlotlyJS
p = plot(scatter(x=[0,1,2], y=[3,6,2]))
open("./example.html", "w") do io
PlotlyBase.to_html(io, p.plot, default_height="400px", default_width="400px")
end Click to copy
nothing