Embedding Plotly Graphs in HTML in Julia

How to embed plotly graphs in an iframe in HTML.


Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.

Note: We are retiring documentation for R, MATLAB, Julia, and F#. Learn more about this change here.

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
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
nothing