Interactive HTML-plots are one of the nice features of plotly / plotlyJS but the standard HTML-output does not include a script tag containing the plotly.js source code (~3MB).
In python this can be achieved via: fig.write_html() and now I wonder, if this can also be achieved via plotlyJS.jl. Any ideas?
Below my example script:
using PlotlyJS
# https://github.com/JuliaPlots/PlotlyJS.jl/issues/366
hdl_plt = PlotlyJS.Plot([1,2,3])
PlotlyJS.savefig(hdl_plt, "online_html.html")
# --- include a script tag containing the plotly.js source code (~3MB) ---
open("offline_html.html", "w") do io
PlotlyJS.PlotlyBase.to_html(io, hdl_plt, include_plotlyjs = "cdn", default_width = "95%", default_height = "95%")
end
And here a solution using PyCall in combination with plotly.py:
using PyCall
go = PyCall.pyimport("plotly.graph_objects")
# ---
fig = go.Figure()
fig.add_trace(go.Scatter(y=[1,2,3]))
fig.show()
fig.write_html("PyCall_offline.html")
fig.write_html("c:\tmp\plt\PyCall_online.html", include_plotlyjs = false)
Thanks for sharing your code (I’m not sure if there is a question behind it?).
FYI, the link for the full documentation for PlotlyBase.to_html is here:
There are a number of options under the include_plotlyjs keyword argument.
Thanks, I was not aware of the command: @doc PlotlyBase.to_html!
The parameter full_html should do the job, as far as I understand,
but it has no impact on the file size, if I switch on and off the variable
The python script exports a offline-HTML file and the file size differs from the online version.
and yes I have a question:
How can I export an offlineHTML under PlotlyJS?
open("offline_html.html", "w") do io
PlotlyJS.PlotlyBase.to_html(io, hdl_plt, include_plotlyjs = "directory",
default_width = "95%", default_height = "95%", full_html=true)
end
Note that include_plotlyjs = "directory". The key is this line in the docs:
will only work when the plotly.min.js file is in the same directory as the output file
So you need to save, say, this: https://cdn.plot.ly/plotly-2.3.0.min.js
to a file in the same directory as your plot’s html file (e.g. right-click and “Save Link as…”) using the filename plotly.min.js
This is already helpful This method can saves place on the disk.
P.S.:
I observed recently that MS-edge-Browser seem to be able, to display also the “on-line” versions
of the HTML-output in off-line mode (situations where no internet-access is available).