Skip to content

Commit 40281d0

Browse files
fonsppankgeorg
andauthored
Use data URL for local plotly asset (#4863)
* Use data URL for local plotly asset * formatting * fix: reviewdog suggestion --------- Co-authored-by: Panagiotis Georgakopoulos <panagiotis.georgakopoulos@juliacomputing.com>
1 parent fcf2e74 commit 40281d0

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/backends/plotly.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt)
10551055

10561056
plotly_url() =
10571057
if _use_local_dependencies[]
1058-
"file:///" * _plotly_local_file_path[]
1058+
_plotly_data_url()
10591059
else
10601060
"https://cdn.plot.ly/$_plotly_min_js_filename"
10611061
end

src/init.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
using Scratch
22
using REPL
3+
import Base64
34

45
const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing)
6+
const _plotly_data_url_cached = Ref{Union{Nothing,String}}(nothing)
7+
_plotly_data_url() =
8+
if _plotly_data_url_cached[] === nothing
9+
_plotly_data_url_cached[] = "data:text/javascript;base64,$(Base64.base64encode(read(_plotly_local_file_path)))"
10+
else
11+
_plotly_data_url_cached[]
12+
end
513
# use fixed version of Plotly instead of the latest one for stable dependency
614
# see github.com/JuliaPlots/Plots.jl/pull/2779
715
const _plotly_min_js_filename = "plotly-2.6.3.min.js"

0 commit comments

Comments
 (0)