PlotlyJS causes errors, can't figure out how to use PlotlyLight - how to use Plotly from Julia?

First post, new to Julia coming from Matlab, so please bear with me, I seem to be struggling with the most basic stuff.

After lots of reading, it seems PlotlyJS is the best plotting package for my use case: interactive exploration of large data sets, mainly time series with datetime x axes (so no Makie for me, I don’t really feel like setting my x ticks manually).

I installed PlotlyJS on a brand new Julia 1.10, and I get an error saying:
Warning: Kaleido is not available on this system. Julia will be unable to save images of any plots
and then
Warning: ErrorException("Could not start Kaleido process")
So as far as I understand, I won’t be able to save any SVG.
I can plot, and the plot is very responsive with large time series, I can also save an HTML file and use the camera button to download a PNG, but that’s not a solution for publication-quality figures.

Searching for documentation, it seems that problems with Kaleido have been present for a long time, with plenty of contradictory information found on forums, so I thought perhaps I should try PlotlyLight (not really knowing whether that would change anything with saving figures).

I installed the PlotlyLight package, and copy/pasted the tutorial found here: GitHub - JuliaComputing/PlotlyLight.jl: Plotly.js via Julia made easy.
I get an error saying Plot() is not defined, or not correctly used, or I don’t know.
Am I missing something obvious?

Thanks for any help!

PS. By the way the link to “export figures” from Home · PlotlyJS is dead, and it is not immediately obvious (to me) that the instructions to save figures are hidden under a menu item called “working with plots”.

No, you don’t.
I tried installing PlotlyJS and got no errors and examples and savefig work, so I failed to reproduce your errors. PlotlyLight gave me errors after I had to install PlotlyKaleido but the errors seem to different from yours.
I suggest that we go back:

(@v1.10) pkg> rm PlotlyLight PlotlyKaleido
...

and try to identify your PlotlyJS problems.
What system do you have:

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, haswell)
  Threads: 5 on 8 virtual cores

Package status seems to be not a problem, as you say you started with a clean Julia 1.10. but perhaps you give too:

(@v1.10) pkg> st
...

You are right here:

You may consider to open an issue at Issues · JuliaPlots/PlotlyJS.jl · GitHub or even better try to make a PR by editing the docs PlotlyJS.jl/docs/src/index.md at master · JuliaPlots/PlotlyJS.jl · GitHub

@jojob68 , welcome.

What editor are you using: VScode, Pluto, or any other?

There is no problem with plotting with PlotlyJS.jl if you use this package inside the VScode editor. If you type and run sequentially:

using PlotlyJS
aa=plot(randn(300))
savefig(aa, "aa.png")

the plot will first appear on the monitor, and then you can save it as you wish (PNG, PDF, SVG,…)

If you use Pluto.jl (a Julia package itself and a remarkable IDE), you should not use PlotlyJS.jl directly; otherwise, you will get the usual Kaleido problems. In Pluto, if you want to plot with the functionalities of PlotlyJS.jl, it would be best if you used PlotlyBase.jl instead, which is the partner of PlotlyJS that, in fact, renders the plots created by the former. For more details on how to use PlotlyJS.jl inside Pluto, check this thread Cannot use PlotlyJS .

Finally, if you want to use PlotlyJS and not bother about what IDE you should use, you can use PlutoPlotly.jl, a package developed by @disberd that mimics the functionalities of PlotlyJS and always works out of the box.

I do a lot of plotting using the functionalities of PlotlyJS.jl and it do not regret it. It is a wonderful package.

1 Like

Both, PlotlyJS and PlotlyLite work for me in the REPL. With PlotlyJS it is plot(...), and with PlotlyLite Plot(...). You need to start the Kaleido server.

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using PlotlyJS
Precompiling PlotlyJS
  6 dependencies successfully precompiled in 7 seconds. 69 already precompiled.

julia> p=plot(x, cos.(x))

julia> x=0:π/56:2π
0.0:0.05609986881410345:6.283185307179586

julia> p=plot(x, cos.(x))
[ Info: Listening on: 127.0.0.1:2228, thread id: 2

julia> savefig(p, "tmp/testplot.svg"; width=1280,height=800)
"tmp/testplot.svg"

and

              _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0 (2023-12-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using PlotlyLight,PlotlyKaleido

julia> PlotlyKaleido.start(mathjax=true)

julia> x=0:π/56:2π
0.0:0.05609986881410345:6.283185307179586

julia> p=Plot(;x=x, y=cos.(x), type="scatter");

julia> savefig(p, "tmp/testplot.svg"; width=1280,height=800)
"tmp/testplot.svg"

Thank you for the answers. I use VSCode, but the error using PlotlyJS is the same when I just open a REPL and try using PlotlyJS.

Here are the versioninfo and package status. Sorry I can’t find a way to not remove libe breaks…

julia> versioninfo() Julia Version 1.10.0 Commit 3120989f39 (2023-12-25 18:01 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: 12 × 13th Gen Intel(R) Core™ i7-1365U WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-15.0.7 (ORCJIT, goldmont) Threads: 1 on 12 virtual cores

Package status:

[336ed68f] CSV v0.10.12 [13f3f980] CairoMakie v0.11.5 [8be319e6] Chain v0.5.0 [35d6a980] ColorSchemes v3.24.0 [5ae59095] Colors v0.12.10 [a93c6f00] DataFrames v1.6.1 [1313f7d8] DataFramesMeta v0.14.1 [e9467ef8] GLMakie v0.9.5 [5903a43b] Infiltrator v1.6.4 [a98d9a8b] Interpolations v0.15.1 [b964fa9f] LaTeXStrings v1.3.1 ⌃ [8913a72c] NonlinearSolve v0.3.22 [9b87118b] PackageCompiler v2.1.17 [f0f68f2c] PlotlyJS v0.18.11 [08abe8d2] PrettyTables v2.3.1 [92933f4c] ProgressMeter v1.9.0 [295af30f] Revise v3.5.13 [40c74d1a] TableView v0.7.2 [f269a46b] TimeZones v1.13.0 [1986cc42] Unitful v1.19.0 [fdbf4ff8] XLSX v0.10.1 [ade2ca70] Dates

Just format it as code in between ``` like:

` ` `
bla
` ` `

without spaces between the ` .

Lets make sure that you have read and execution rights in artifacts. Please open a windows CMD shell, just type cmd at Start and run it.
Move to .julia:

cd c:\users\Oli\.julia

Use your username instead if Oli, because thats me :wink:

Run the following command:

icacls artifacts /grant everyone:(OI)(CI)RX /C /T

Depending on your language setting everyone needs to be something else, for me, german, its jeder. If you don’t find the right thing you can use your username too, like Oli in my case, perhaps its better anyways, so:

icacls artifacts /grant Oli:(OI)(CI)RX /C /T

This grants recursively read and exec rights to everything in folder artifacts, so you can be sure that you are allowed to run the kaleido.exe which is located on my system in c:\Users\Oli\.julia\artifacts\7914a56da888d6a06d00c87f97e873c60e97acc7\bin\kaleido.exe
You can locate your path and apply above command just to the folder 7914a56da888d6a06d00c87f97e873c60e97acc7 in my case.

Perhaps PlotlyJS is good now.

Depending on your windows skill you are ok with this help. If not just ask and we see whats wrong.

I use PlotlyJS v0.18.12, and Julia v1.10.0 on a Windows 10 machine. No problem with my plotting using PlotlyJS in either the REPL or VScode. In the REPL this is what I get:

You have a lot of packages in the main environment. Maybe, some package precludes you from updating PlotlyJS to the latest version. Your version is v0.18.11 while the latest one is v0.18.12. Can you try to update PlotlyJS and see what you get by doing in Julia mode:

import Pkg
Pkg.update("PlotlyJS")

Thanks for the suggestions. I ran the command to change access rights, it made no difference.
I then updated all packages, it did find PlotlyJS 0.18.12 (which is very recent, since I installed the former version 2 days ago!) and installed it. Again, no difference, same error.
I assume this is normal, but out of curiosity I tried to run kaleido.cmd which is in the artifacts directeory and it gives this error:

[0116/184426.256:WARNING:resource_bundle.cc(405)] locale_file_path.empty() for locale
[0116/184426.310:WARNING:headless_browser_main_parts.cc(83)] Cannot create Pref Service with no user data dir.
{"code": 1, "message": "No Scope Specified", "result": null, "version": "0.2.1"}

If there is a chance it can work by deleting julia entirely and reinstalling, this time with PlotlyJS 0.18.12 directly (and not upgrading from 0.18.11), I am willing to try, but this will take quite a bit of time so other suggestions are welcome.

I don’t think so.
I check for the new error and will be back.

I get the same error in a CMD shell but PlotlyJS works for me.

Could you please try again in the following way:

First we need the complete path to kaleido_jll:

julia> using PlotlyJS.Kaleido_jll

julia> Kaleido_jll.artifact_dir
"C:\\Users\\Oli\\.julia\\artifacts\\7914a56da888d6a06d00c87f97e873c60e97acc7"

Now run in CMD (with your path of course):

C:\\Users\\Oli\\.julia\\artifacts\\7914a56da888d6a06d00c87f97e873c60e97acc7\\kaleido.cmd plotly --disable-gpu --no-sandbox

This is the command constructed in kaleido.jl.
I have to stop the running process with Ctrl-C and I get the output:

[0117/094045.973:WARNING:resource_bundle.cc(405)] locale_file_path.empty() for locale
[0117/094046.001:WARNING:headless_browser_main_parts.cc(83)] Cannot create Pref Service with no user data dir.
{"code": 0, "message": "Success", "result": null, "version": "0.2.1"}
[0117/094046.031:ERROR:gpu_init.cc(430)] Passthrough is not supported, GL is swiftshader
^CBatchvorgang abbrechen (J/N)? J

Please report your output with your complete command line your are running. I have a suspicion.

Thank you for your continued effort to help!

I ran the command, and I got an “access denied” error. I then re-ran the command to change permissions that you recommended before, and it gave a different result.
So I have to correct my statement above that " I ran the command to change access rights, it made no difference." I think what happened is that I didn’t copy/paste the last switch(es) /C /T, so the command ran without an error but didn’t do much. This time, when I ran it again, I got a long list of files for which the access rights were changed. I apologize for my error and the misleading statement.

But I still need help, because the only difference with the “corrected” access rights is that now, using PlotlyJS results in Julia hanging (I let is run for a full minute) and if I interrupt (CTRL-C) I get the same error as before about Kaleido not being available.

Running the command you suggest (C:\Users.…\kaleido.cmd plotly --disable-gpu --no-sandbox) gives this:

[0117/132424.316:WARNING:resource_bundle.cc(405)] locale_file_path.empty() for locale
[0117/132424.332:WARNING:headless_browser_main_parts.cc(83)] Cannot create Pref Service with no user data dir.
{"code": 0, "message": "Success", "result": null, "version": "0.2.1"}
[0117/132424.354:ERROR:gpu_init.cc(430)] Passthrough is not supported, GL is swiftshader
^CTerminate batch job (Y/N)? y

“Just hanging” is worse than before…

Running kaleido.cmd is now fine, good, some success.

It still may be something with your rights perhaps it’s the rights of the whole .julia folder. Typically the access rights in artifacts is inherited from the parent folder.

So lets do it again for .julia but now with write access too (full access), that’s how it should be in your home folder:

icacls .julia /grant YOUR_NAME:(OI)(CI)F /C /T

What’s your username? It’s no problem to tell us. If you don’t like: does it contain spaces or other special characters?

After changing the access rights, you may also try to reinstall, because perhaps some installations went wrong or partially wrong without proper access rights in .julia. But don’t delete .julia, like to be clean, because the access rights might be wrong again later on.

I changed the rights on the whole .julia folder, it took a while to run and said successfully processed 78022 files; Failed processing 0 files.
After that, using PlotlyJS still hangs. One thing I didn’t notice before, it only hangs the first time. If I run using PlotlyJS again without restarting Julia, it completes immediately. But savefig() to a png fails (does work to HTML)
My username is 3 letters like yours, no spaces no accents nothing special. And I am an administrator on the machine (but I still got the “access denied” when trying to run the .cmd the first time, so you were on to something…)
I will try reinstalling Julia from scratch, but just to make sure, here is what I would do:

  • uninstall Julia from Windows “add or remove programs”
  • delete the contents of .julia under my username, but keep the folder itself.
  • reinstall Julia

Is that the idea?

Yes.

But only if you really are new to Julia. E.g. the .julia\dev folder is important not to delete, as it holds your development environments, which typically don’t want to be lost. But I think you said you started from scratch, so it should be fine.

When you deinstalled and removed everything you may consider to install Julia using juliaup. You can get it from the Windows Store (just search for Julia). It helps a lot in the longer run. See GitHub - JuliaLang/juliaup: Julia installer and version multiplexer for installation and how to proceed. It should be no difference for the PlotlyJS problem.

Going to bed now, back in ~10h.

Willl try, thanks!

When I do this I get immediately an error:

julia> PlotlyKaleido.start(mathjax=true)                                                                                                                                                                                          
ERROR: Kaleido startup failed.                                                                                                                                                                                                    
Stacktrace:                                                                                                                                                                                                                       
 [1] error(s::String)                                                                                                                                                                                                             
   @ Base .\error.jl:35                                                                                                                                                                                                           
 [2] start(; plotly_version::Missing, mathjax::Bool, mathjax_version::VersionNumber, kwargs::@Kwargs{})                                                                                                                           
   @ PlotlyKaleido C:\Users\pkonl\SublimeJulia_1_10_0\assets\.julia-1.10.0-depot\packages\PlotlyKaleido\FXxni\src\PlotlyKaleido.jl:92                                                                                             
 [3] top-level scope                                                                                                                                                                                                              
   @ REPL[9]:1      

I think it is broken on windows with Julia 1.10.

Thanks again for your help. I am pleased to report that I was finally able to save a PlotlyJS figure as svg, after this:

  1. Uninstall Julia and delete .julia folder manually (I know you said not, but I was curious to see whether that really made a difference…)
  2. Install Julia 1.10 from the Windows 64 installer
  3. Add PlotlyJS (as the only package I added, right in the main @v1.10 environment)
  4. Change the permissions on the artifacts folder with the instruction (in Windows CMD, not in Julia):
    icacls C:\Users\%UserName%\.julia\7914a56da888d6a06d00c87f97e873c60e97acc7 /grant %UserName%:(OI)(CI)RX /C /T
    (the 79..acc7 directory is the one where kaleido.cmd can be found)

After step 3, I was getting the same error as before. After changing the permissions according to your instructions, it worked. Compared to my previous attempt, the difference is in other packages that I had installed (in a somewhat random order, so I would not be able to reproduce that). So either I am missing something, or the hanging was caused by some other package?

2 Likes

I wanted to try to find which package was causing a conflict, and I found something else that could be interesting. I did exactly the same steps as above, but this time, before adding PlotlyJS (as the very first package added to a clean setup) I created a shared @tmp environment (because I thought this would not “pollute” my main installation and I could do multiple attempts). What I got is this:

  1. clean julia install 1.10 from windows 64 installer
  2. activate @tmp environment, add PlotlyJS to that environment
  3. try using PlotlyJS, I get the (now usual) error, so I change the permissions as instructed by oheil and restart Julia.
  4. Now, after activating @tmp, using PlotlyJS hangs

Why is there a difference whether I install PlotlyJS in the main environment compared to when I install it in a @tmp environment?

It works for me without any issues (Julia 1.10, Windows 11 (at home) and Windows 10 (work)).

Awesome!

For me there is no difference, it just works in both scenarios.

Still I believe there is an access right problem inherited from your home directory. I recommend, to avoid similar future problems with other packages, to set “full access” at least to the .julia folder with above command (which enables inheritance for everything new beneath .julia. The command is:

icacls .julia /grant YOUR_NAME:(OI)(CI)F /C /T