diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 005ecead..ed7a48d1 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -883,8 +883,6 @@ plotly_series_json(plt::Plot) = JSON.json(plotly_series(plt), 4) html_head(plt::Plot{PlotlyBackend}) = plotly_html_head(plt) html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt) -const ijulia_initialized = Ref(false) - function plotly_html_head(plt::Plot) plotly = use_local_dependencies[] ? ("file:///" * plotly_local_file_path[]) : "https://cdn.plot.ly/$(_plotly_min_js_filename)" @@ -893,20 +891,11 @@ function plotly_html_head(plt::Plot) mathjax_file = include_mathjax != "cdn" ? ("file://" * include_mathjax) : "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML" mathjax_head = include_mathjax == "" ? "" : "\n\t\t" - if isijulia() && !ijulia_initialized[] - # using requirejs seems to be key to load a js depency in IJulia! - # https://requirejs.org/docs/start.html - # https://github.com/JuliaLang/IJulia.jl/issues/345 - display("text/html", """ - - """) - ijulia_initialized[] = true + if isijulia() + mathjax_head + else + "$mathjax_head" end - return "$mathjax_head" end function plotly_html_body(plt, style = nothing) @@ -914,12 +903,22 @@ function plotly_html_body(plt, style = nothing) w, h = plt[:size] style = "width:$(w)px;height:$(h)px;" end + + requirejs_prefix = "" + requirejs_suffix = "" + if isijulia() + requirejs_prefix = "require(['Plotly'], function (Plotly) {" + requirejs_suffix = "});" + end + uuid = UUIDs.uuid4() html = """
""" html diff --git a/src/init.jl b/src/init.jl index 22bb4b51..d340fda7 100644 --- a/src/init.jl +++ b/src/init.jl @@ -89,6 +89,23 @@ function __init__() use_local_dependencies[] = use_local_plotlyjs[] + if isijulia() + # require.js adds .js automatically + plotly_no_ext = + use_local_dependencies[] ? ("file:///" * plotly_local_file_path[]) : "https://cdn.plot.ly/$(_plotly_min_js_filename)" + plotly_no_ext = plotly_no_ext[1:end-3] + + display("text/html", """ + + """) + end + @require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" begin _show(io::IO, mime::MIME"image/png", plt::Plot{<:PDFBackends}) = _show_pdfbackends(io, mime, plt)