diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 1c251c639..12f81ad60 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -1055,7 +1055,7 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt) plotly_url() = if _use_local_dependencies[] - "file:///" * _plotly_local_file_path[] + _plotly_data_url() else "https://cdn.plot.ly/$_plotly_min_js_filename" end diff --git a/src/init.jl b/src/init.jl index aa58c2bb9..f2322c2ee 100644 --- a/src/init.jl +++ b/src/init.jl @@ -1,7 +1,14 @@ using Scratch using REPL +import Base64 const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing) +const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing) +_plotly_data_url() = if _plotly_data_url_cached[] === nothing + _plotly_data_url_cached[] = "data:text/javascript;base64,$(Base64.base64encode(read(_plotly_local_file_path)))" + else + _plotly_data_url_cached[] + end # use fixed version of Plotly instead of the latest one for stable dependency # see github.com/JuliaPlots/Plots.jl/pull/2779 const _plotly_min_js_filename = "plotly-2.6.3.min.js"