Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the plotly.min.js file from PlotlyJS.jl #4862

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ RecipesPipeline = "01d81517-befc-4cb6-b9ec-a95719d0359c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down Expand Up @@ -75,7 +74,7 @@ PGFPlotsX = "1"
PlotThemes = "2, 3"
PlotUtils = "1"
PlotlyBase = "0.7 - 0.8"
PlotlyJS = "0.18"
PlotlyJS = "0.18.12"
PlotlyKaleido = "1"
PrecompileTools = "1"
PyPlot = "2"
Expand All @@ -85,7 +84,6 @@ RecipesPipeline = "0.6.10"
Reexport = "0.2, 1"
RelocatableFolders = "0.3, 1"
Requires = "1"
Scratch = "1"
Showoff = "0.3.1, 1"
Statistics = "1"
StatsBase = "0.33, 0.34"
Expand Down
4 changes: 1 addition & 3 deletions ext/IJuliaExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const IJulia =

function _init_ijulia_plotting()
# IJulia is more stable with local file
Plots._use_local_plotlyjs[] =
Plots._plotly_local_file_path[] === nothing ? false :
isfile(Plots._plotly_local_file_path[])
Plots._use_local_plotlyjs[] = true

ENV["MPLBACKEND"] = "Agg"
end
Expand Down
2 changes: 1 addition & 1 deletion src/backends/plotly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ html_body(plt::Plot{PlotlyBackend}) = plotly_html_body(plt)

plotly_url() =
if _use_local_dependencies[]
"file:///" * _plotly_local_file_path[]
"file:///" * _plotly_local_file_path
else
"https://cdn.plot.ly/$_plotly_min_js_filename"
end
Expand Down
3 changes: 1 addition & 2 deletions src/backends/web.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ function standalone_html_window(plt::AbstractPlot)
old = _use_local_dependencies[] # save state to restore afterwards
# if we open a browser ourself, we can host local files, so
# when we have a local plotly downloaded this is the way to go!
_use_local_dependencies[] =
_plotly_local_file_path[] === nothing ? false : isfile(_plotly_local_file_path[])
_use_local_dependencies[] = true
filename = write_temp_html(plt)
open_browser_window(filename)
# restore for other backends
Expand Down
10 changes: 3 additions & 7 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Scratch
using REPL
import PlotlyJS

Copy link
Contributor Author

@fonsp fonsp Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isentropic It looks like this caused a test failure because PlotlyJS is not a dependency. How does that work? I thought PlotlyJS is always loaded by default?

When I run import Plots; plotly(); plot(1:10) in Pluto, does that load the PlotlyJS package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run import Plots; plotly(); plot(1:10) in Pluto, does that load the PlotlyJS package?

No, only import Plots; plotlyjs(); plot(1:10) will load PlotlyJS, plotly() is special in that it is the only backend that is usable without any 3rd party (julia) package, but it can only display to a web browser, while plotlyjs has a standalone display via Blink.jl

const _plotly_local_file_path = Ref{Union{Nothing,String}}(nothing)
const _plotly_local_file_path = PlotlyJS._js_path
# 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"
const _plotly_min_js_filename = "plotly-$(PlotlyJS._js_version).min.js"

const _use_local_dependencies = Ref(false)
const _use_local_plotlyjs = Ref(false)
Expand All @@ -23,10 +23,6 @@ end

function _plots_plotly_defaults()
if bool_env("PLOTS_HOST_DEPENDENCY_LOCAL", "false")
_plotly_local_file_path[] =
fn = joinpath(@get_scratch!("plotly"), _plotly_min_js_filename)
isfile(fn) ||
Downloads.download("https://cdn.plot.ly/$(_plotly_min_js_filename)", fn)
_use_local_plotlyjs[] = true
end
_use_local_dependencies[] = _use_local_plotlyjs[]
Expand Down
5 changes: 1 addition & 4 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
end

@testset "Plotly standalone" begin
@test Plots._plotly_local_file_path[] ≡ nothing
temp = Plots._use_local_dependencies[]
withenv("PLOTS_HOST_DEPENDENCY_LOCAL" => true) do
Plots._plots_plotly_defaults()
@test Plots._plotly_local_file_path[] isa String
@test isfile(Plots._plotly_local_file_path[])
@test isfile(Plots._plotly_local_file_path)
@test Plots._use_local_dependencies[] = true
end
Plots._plotly_local_file_path[] = nothing
Plots._use_local_dependencies[] = temp
end

Expand Down
Loading