# Offline HTML plot

**URL:** <https://discourse.julialang.org/t/offline-html-plot/93609>\
**Category:** Visualization\
**Tags:** plotting, plotlyjs\
**Created:** [January 27, 2023, 8:20am UTC](https://discourse.julialang.org/t/offline-html-plot/93609 "2023-01-27T08:20:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [January 27, 2023, 8:20am UTC](https://discourse.julialang.org/t/offline-html-plot/93609/1 "2023-01-27T08:20:55Z")

</div>

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:

```julia
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`:

```julia
    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)

```

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [January 27, 2023, 10:34am UTC](https://discourse.julialang.org/t/offline-html-plot/93609/2 "2023-01-27T10:34:54Z")

</div>

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:

> **[Interactive](https://plotly.com/julia/interactive-html-export/)**
>
> Plotly

There are a number of options under the `include_plotlyjs` keyword argument.

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [January 27, 2023, 12:02pm UTC](https://discourse.julialang.org/t/offline-html-plot/93609/3 "2023-01-27T12:02:21Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [January 27, 2023, 12:21pm UTC](https://discourse.julialang.org/t/offline-html-plot/93609/4 "2023-01-27T12:21:10Z")

</div>

I would start with this:

```julia
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](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**

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [January 30, 2023, 2:10pm UTC](https://discourse.julialang.org/t/offline-html-plot/93609/5 "2023-01-30T14:10:11Z")

</div>

> [@jd-foster](#):
>
> include\_plotlyjs = “directory”

Thanks jd! - I see, with this option the following line inside the HTML:

```julia
<script src="https://cdn.plot.ly/plotly-2.3.0.min.js"></script>

```

changes to:

```julia
<script src="plotly.min.js"></script>

```

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).

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 28, 2023, 8:05am UTC](https://discourse.julialang.org/t/offline-html-plot/93609/6 "2023-02-28T08:05:36Z")

</div>

It seems as if a workaround exist:  
[# PlotlyJS.PlotlyBase.to\_html() does not export a stand alone HTML](https://github.com/JuliaPlots/PlotlyJS.jl/issues/459)
