# Using environment variables with Plots

**URL:** <https://discourse.julialang.org/t/using-environment-variables-with-plots/132842>\
**Category:** General Usage\
**Tags:** plots, plotlyjs\
**Created:** [October 3, 2025, 7:22am UTC](https://discourse.julialang.org/t/using-environment-variables-with-plots/132842 "2025-10-03T07:22:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![J-Holger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-holger/32/215895_2.png) [@J-Holger](https://discourse.julialang.org/u/J-Holger)\
**Post date:** [October 3, 2025, 7:22am UTC](https://discourse.julialang.org/t/using-environment-variables-with-plots/132842/1 "2025-10-03T07:22:40Z")

</div>

Hi!

I’m using the `Plots` (v1.41.1) package to create and save figures in Julia. Currently, I’m using `PlotlyJS` as backend and everything works well. The problem is that my application does not have access to internet so I want the rendered HTML figures from `Plots` to point to a local plotly JavaScript file. My current solution is that I simply change the content of the HTML files by string-handling and regexp which obviously is not something that I prefer…

I have looked into the source code of `Plots` and found that there exists an environment variable `PLOTSBASE_HOST_DEPENDENCY_LOCAL` which appears to do what I want. My problem is that it doesn’t work and the HTML is still pointing to an online JavaScript resource. Can someone help me how to use the environment variables in `Plots` package correct?

My current implementation looks something like this:

```julia-auto
using Scratch

# Copy a local plotly.js file into the "plotly" scratch space.
# This is how I interpret the use of the ENV-variable in init.jl code in PlotsBase.
plotly_scratch = @get_scratch!("plotly")
source_path = joinpath(@ __DIR__ , "plotly-2.3.0.min.js")
dest_path = joinpath(plotly_scratch, "plotly-2.3.0.min.js")
cp(source_path, dest_path; force=true)

# Set the environment variable.
ENV["PLOTSBASE_HOST_DEPENDENCY_LOCAL"] = "1"

# Rebuild the Plots packages to make sure the init code is evaluated again.
Pkg.build("PlotlyBase")
Pkg.build("PlotlyKaleido")
Pkg.build("PlotlyJS")
Pkg.build("Plots")

using Plots

plotlyjs()
plt = plot([1, 3], [10, 30])
savefig(plt, "plt.html")
```

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 3, 2025, 8:01am UTC](https://discourse.julialang.org/t/using-environment-variables-with-plots/132842/2 "2025-10-03T08:01:35Z")

</div>

I think you need to give it the path to the plotly file in that environment variable.

Also you seem to read the documentation for Plots 2.0 (which is not released) on Plots v1.x the variable is called `PLOTS_HOST_DEPENDENCY_LOCAL`

---

<div class="post-metadata">

**Author:** ![J-Holger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-holger/32/215895_2.png) [@J-Holger](https://discourse.julialang.org/u/J-Holger)\
**Post date:** [October 6, 2025, 12:39pm UTC](https://discourse.julialang.org/t/using-environment-variables-with-plots/132842/3 "2025-10-06T12:39:07Z")

</div>

Thanks for your response!

You are absolutely correct that I was using the env-variable for `Plots v2`, thanks for pointing that out.

After trying out a bit more with a local copy of `Plots v1.41.1` where I fixed a small bug reading the local plotlyjs file and exposing the ` __init__ ()` function to be able to dynamically set the env-variables the generated HTML is indeed using a local plotlyjs script!

However, one problem to enable viewing the plots offline is still present. The generated HTML is pointing to an online `require.js` resource. I changed this by enabling an option to use a local resource in similar fashion as for plotly.

So for future reference, `Plots v.1.41.1` does not support saving `PlotlyJS` HTML plots using local `plotly.js` and `require.js` resources. Support for local `plotly.js` is enabled by a small bug fix and will probably be fixed in future versions.
