PlotlyJS while on ssh server

Viewed 95

I am using my laboratory SSH server and would like to use PlotlyJS in Julia. However the minimal following code doesn't work and I have no idea nor enough knowledge to determine why.

julia> using PlotlyJS
julia> plot(1:5)  
Error showing value of type PlotlyJS.SyncPlot:  
ERROR: IOError: connect: connection refused (ECONNREFUSED)  
Stacktrace:  
 [1] wait_connected(::Sockets.TCPSocket) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/Sockets/src/Sockets.jl:525  
 [2] connect at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/Sockets/src/Sockets.jl:560 [inlined]  
 [3] connect(::Sockets.IPv4, ::Int64) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/Sockets/src/Sockets.jl:546  
 [4] try_connect(::Sockets.IPv4, ::Vararg{Any,N} where N; interval::Float64, attempts::Int64) at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/process.jl:79  
 [5] try_connect at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/process.jl:77 [inlined]  
 [6] init(; debug::Bool) at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/process.jl:93  
 [7] shell(; debug::Bool) at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/process.jl:149  
 [8] shell at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/process.jl:144 [inlined]  
 [9] #Window#14 at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/window.jl:89 [inlined]  
 [10] Blink.AtomShell.Window(::Dict{String,Int64}) at /home/MYLAB/MYNAME/.julia/packages/Blink/mwJC9/src/AtomShell/window.jl:89  
 [11] display_blink(::PlotlyJS.SyncPlot) at /home/MYLAB/MYNAME/.julia/packages/PlotlyJS/4jzLr/src/display.jl:169  
 [12] display(::PlotlyJS.PlotlyJSDisplay, ::PlotlyJS.SyncPlot) at /home/MYLAB/MYNAME/.julia/packages/PlotlyJS/4jzLr/src/display.jl:160  
 [13] display(::Any) at ./multimedia.jl:328  
 [14] #invokelatest#1 at ./essentials.jl:710 [inlined]  
 [15] invokelatest at ./essentials.jl:709 [inlined]  
 [16] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:238  
 [17] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:223  
 [18] (::REPL.var"#do_respond#54"{Bool,Bool,REPL.var"#64#73"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:822  
 [19] #invokelatest#1 at ./essentials.jl:710 [inlined]  
 [20] invokelatest at ./essentials.jl:709 [inlined]  
 [21] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/LineEdit.jl:2355  
 [22] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:1144  
 [23] (::REPL.var"#38#42"{REPL.LineEditREPL,REPL.REPLBackendRef})() at ./task.jl:356  
1 Answers

Well SSH does not forward graphic interfaces to your local machines automatically. Thus PlotlyJS tries to open a graphic interface, but it fails, since it can't do that. You need to enable X11Forwarding when you connect to the server and it needs to be allowed by the server. Using a linux machine the command is then usually

ssh -X username@server.org

where the -X option is for port forwarding. A guide on how to use X11Forwading can be found here.

That said, I would suggest you to use the Plots package of Julia and not the backend package PlotlyJS to work with plots, since it has more functionality and it more user friendly. You can use the PlotlyJS backend with:

using Plots
plotlyjs()

If you use Plots be careful, since not all backends support this kind of forwarding, e.g., GR does not work.

Finally, I really discourage you to plot from a server to your local machine, as it is really slow and does not make much sense in my opinion.

Another possibility is to suppress the displaying of the plot to save the plot and copy it to your local machine and then open it. This is done through a semicolon ;, since plots are only displayed when returned. Thus:

using Plots #(or PlotlyJS as you wish)
p = plot();
savefig(p, "fig.png")
Related