Coder Social home page Coder Social logo

plotlyjs.jl's Introduction

PlotlyJS

Build Status project chat

Julia interface to plotly.js visualization library.

This package constructs plotly graphics using all local resources. To interact or save graphics to the Plotly cloud, use the Plotly package.

Installation

If you have issues building this package because of installation of the MbedTLS package please see this issue.

Jupyterlab

If you will be using this package from within Jupyterlab, please also install the plotly jupyterlab extension by running:

jupyter labextension install jupyterlab-plotly

See the jupyterlab extension documentation for more details.

plotlyjs.jl's People

Contributors

beastyblacksmith avatar caimichael avatar cc7768 avatar cstjean avatar ericforgy avatar femtocleaner[bot] avatar fonsp avatar ghuba avatar github-actions[bot] avatar gitter-badger avatar halars avatar jobjob avatar liozou avatar matthieugomez avatar mikeinnes avatar mmcky avatar mzaffalon avatar pfitzseb avatar rasmushenningsson avatar scottpjones avatar sglyon avatar sjkelly avatar ssfrr avatar stefankarpinski avatar tbreloff avatar thomasjm avatar timholy avatar totalverb avatar twavv avatar vpetukhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plotlyjs.jl's Issues

restyle! needs to be fixed... Julia and javascript have different semantics

So here's the problem. Suppose you are trying to completely reset x and y on a trace 1 to be [1, 2, 3] and [4, 5, 2] respectively.

The natural way to do this would be something like

restyle!(p, 1, x=[1, 2, 3], y=[4, 5, 2])

or

restyle!(p, 1, Dict(:x=>[1, 2, 3], :y=>[4, 5, 2])

This would correctly set the Plot object, but on the javascript side the trace would have x and y set to 1 and 4, respectively.

From the function reference if you want to change an attribute that takes on an array, you need to pass an array of arrays. In Julia we might call them matrices.

To get the display to update properly you would need to do something like

restyle!(p, 1, x=[1 2 3]', y=[4 5 2]')

This will get translated to the javascript:

Plotly.restyle(p, {"x": [[1, 2, 3]], "y": [[4, 5, 2]]}, 0)

which is exactly what we need to do. However, now the Plot object will have a matrix for the x and y attributes and if you try to copy the plot and redisplay it won't work.

Because we had different semantics in Julia and js we are now out of sync

Any ideas how to best resolve this? Which semantics to we enforce?

cc @tbreloff

Electron backend on Windows throws error

When I try to plot on the command line through the Electron backend I get:

julia> using Plots

julia> plotlyjs()
Plots.PlotlyJSBackend()

julia> plot(1:10)
[Plots.jl] Initializing backend: plotlyjs
module.js:338
    throw err;
    ^

Error: Cannot find module 'app'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

    at Object.<anonymous> (C:\Users\ezzkc\.julia\v0.4\Blink\src\AtomShell\main.js:1:90)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

Plotting in Jupyter works as intended.

I did run Blink.AtomShell.install() as per manual instructions. I get the same error if I use PlotlyJS directly.

Cloud

Is there a way to save a graph in the cloud? If I dot a plot in PlotlyJS, click on "Save and edit plot in cloud", I end up on a webpage that does not show the plot I've just created (I end up on the default dataset with giraffes orangutans monkeys).

Loading PlotlyJS fails on Julia V0.5-rc1

I am able to Pkg.add(PlotlyJS) but loading it fails

./julia                                                                                                                 julia-dev/git/tags/v0.5.0-rc1 
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.0-rc1+0 (2016-08-04 08:48 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-apple-darwin15.6.0

julia> using PlotlyJS
WARNING: symbol is deprecated, use Symbol instead.
 in depwarn(::String, ::Symbol) at ./deprecated.jl:64
 in symbol(::SubString{String}, ::Vararg{SubString{String},N}) at ./deprecated.jl:30
 in bname(::Symbol) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:17
 in match(::Symbol, ::Symbol, ::Dict{Any,Any}) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:86
 in match_inner(::Expr, ::Expr, ::Dict{Any,Any}) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:63
 in match(::Expr, ::Expr, ::Dict{Any,Any}) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:89
 in match_inner(::Expr, ::Expr, ::Dict{Any,Any}) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:63
 in match(::Expr, ::Expr, ::Dict{Any,Any}) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:89
 in trymatch(::Expr, ::Expr) at /Users/abisen/.julia/v0.5/MacroTools/src/match.jl:105
 in macro expansion at /Users/abisen/.julia/v0.5/MacroTools/src/macro.jl:29 [inlined]
 in (::MacroTools.##21#22)(::Expr) at /Users/abisen/.julia/v0.5/MacroTools/src/utils.jl:91
 in prewalk(::MacroTools.##21#22, ::Expr) at /Users/abisen/.julia/v0.5/MacroTools/src/utils.jl:62
 in shortdef(::Expr) at /Users/abisen/.julia/v0.5/MacroTools/src/utils.jl:90
 in macro expansion at /Users/abisen/.julia/v0.5/MacroTools/src/macro.jl:57 [inlined]
 in @hook(::Any) at /Users/abisen/.julia/v0.5/Requires/src/hook.jl:4
 in macro expansion at /Users/abisen/.julia/v0.5/Requires/src/require.jl:9 [inlined]
 in (::Requires.##8#9)() at /Users/abisen/.julia/v0.5/Requires/src/init.jl:17
 in __init__() at /Users/abisen/.julia/v0.5/Requires/src/init.jl:24
 in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:174
 in _require_from_serialized(::Int64, ::Symbol, ::Bool) at ./loading.jl:202
 in require(::Symbol) at ./loading.jl:332
 in stale_cachefile(::String, ::String) at ./loading.jl:562
 in recompile_stale(::Symbol, ::String) at ./loading.jl:579
 in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:173
 in _require_from_serialized(::Int64, ::Symbol, ::Bool) at ./loading.jl:202
 in require(::Symbol) at ./loading.jl:332
 in include_from_node1(::String) at ./loading.jl:426
 in eval(::Module, ::Any) at ./boot.jl:234
 in require(::Symbol) at ./loading.jl:357
 in eval(::Module, ::Any) at ./boot.jl:234
 in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
 in macro expansion at ./REPL.jl:95 [inlined]
 in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:46
while loading /Users/abisen/.julia/v0.5/PlotlyJS/src/PlotlyJS.jl, in expression starting on line 5
ERROR: LoadError: InitError: type Method has no field func
 in macro expansion at /Users/abisen/.julia/v0.5/Requires/src/require.jl:9 [inlined]
 in (::Requires.##8#9)() at /Users/abisen/.julia/v0.5/Requires/src/init.jl:17
 in __init__() at /Users/abisen/.julia/v0.5/Requires/src/init.jl:24
 in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:174
 in _require_from_serialized(::Int64, ::Symbol, ::Bool) at ./loading.jl:202
 in require(::Symbol) at ./loading.jl:332
 in stale_cachefile(::String, ::String) at ./loading.jl:562
 in recompile_stale(::Symbol, ::String) at ./loading.jl:579
 in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:173
 in _require_from_serialized(::Int64, ::Symbol, ::Bool) at ./loading.jl:202
 in require(::Symbol) at ./loading.jl:332
 in include_from_node1(::String) at ./loading.jl:426
 in eval(::Module, ::Any) at ./boot.jl:234
 in require(::Symbol) at ./loading.jl:357
during initialization of module Requires
while loading /Users/abisen/.julia/v0.5/PlotlyJS/src/PlotlyJS.jl, in expression starting on line 5

julia> 

Plots.jl animations

This example from the Plots.jl examples for PlotlyJS doesn't work in a Jupyter notebook:

p = plot([sin,cos],zeros(0),leg=false)
anim = Animation()
for x = linspace(0,10π,100)
    push!(p,x,Float64[sin(x),cos(x)])
    frame(anim)
end

MethodError: `isactive` has no method matching isactive(::PlotlyJS.JupyterDisplay)
while loading In[31], in expression starting on line 3

 in savefig at /Users/cedric/.julia/v0.4/PlotlyJS/src/savefig.jl:118
 in writemime at /Users/cedric/.julia/v0.4/Plots/src/output.jl:154
...

I've seen that isactive is defined for Electron, does that mean that it would work under Atom?

How to save the JSON object

Hi! I want to export/save the JSON plot data, in order to load it in a HTML and modify it using JS to interact with the plot in different ways. Is it possible to do that? Thanks!

Implement `attr` function with kwarg + _ mini-language

The basic idea is to write a function that takes no positional arguments, only keywords so that we can easily set nested properties.

Example:

attr(x_y_z_w = 100) # ==> Dict(:x => Dict(:y => :Dict(:z => Dict(:w => 100))))

Events

Are events (e.g., click, hover) supported at this time?

Thanks!

Error message with savefig

Thanks for the great package. Could you explain the following error messages?

julia> using PlotlyJS

julia> using Blink

julia> function linescatter1()
           trace1 = scatter(;x=1:4, y=[10, 15, 13, 17], mode="markers")
           trace2 = scatter(;x=2:5, y=[16, 5, 11, 9], mode="lines")
           trace3 = scatter(;x=1:4, y=[12, 9, 15, 12], mode="lines+markers")
           plot([trace1, trace2, trace3])
           return [trace1, trace2, trace3]
       end
linescatter1 (generic function with 1 method)

julia> P = Plot(linescatter1());

julia> savefig(P,"testsave.html",:local)
ERROR: PlotlyJS.savefig not available without a frontend. Try calling `PlotlyJS.savefig(SyncPlot(p))` instead
 in error at /Applications/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib
 in savefig at /Users/greghenselman/.julia/v0.4/PlotlyJS/src/savefig.jl:196

julia> PlotlyJS.savefig(SyncPlot(P))
ERROR: UndefVarError: SyncPlot not defined

Thanks for your help.

Properties with underscores not handled correctly on trace creation

This function generates a plot with error bars:

function errorplot(x, y)
    t = scatter(x=x, y=y, marker_size=10, mode="markers")
    t.fields[:error_y]=Dict(
        :type => "data",
        :array => rand(length(y)),
        :visible => true)
    println(t.fields)
    plot(t)

But this version (setting the error bars at creation time) does not:

function errorplot(x, y)
    t = scatter(x=x, y=y, marker_size=10, mode="markers",
        error_y=Dict(
            :type => "data",
            :array => rand(length(y)),
            :visible => true))
    println(t.fields)
    plot(t)

Seems like the underscore nesting is getting a little overzealous.

savefig hangs if the plot hasn't been displayed for long enough

This happens either if the plot is not displayed, or if the plot is displayed but then savefig is immediately called (presumably the Blink setup is still happening). This is how I reproduce:

julia> using Plots; plotlyjs(); plot(rand(10),show=true); savefig("/tmp/tmp.png")
^CError handling websocket connection:
InterruptException:EOFError: read end of file
 in read at ./iobuffer.jl:88 [inlined]
 in read(::TCPSocket, ::Type{UInt8}) at ./stream.jl:787
 in byteat at /home/tom/.julia/v0.5/JSON/src/Parser.jl:55 [inlined]
 in current at /home/tom/.julia/v0.5/JSON/src/Parser.jl:66 [inlined]
 in chomp_space! at /home/tom/.julia/v0.5/JSON/src/Parser.jl:110 [inlined]
 in parse_value(::JSON.Parser.StreamingParserState{TCPSocket}, ::Type{T}) at /home/tom/.julia/v0.5/JSON/src/Parser.jl:153
 in #parse#2(::Type{Dict{String,Any}}, ::Function, ::TCPSocket) at /home/tom/.julia/v0.5/JSON/src/Parser.jl:392
 in macro expansion at /home/tom/.julia/v0.5/Lazy/src/macros.jl:258 [inlined]
 in macro expansion at /home/tom/.julia/v0.5/Blink/src/AtomShell/process.jl:94 [inlined]
 in (::Blink.AtomShell.##6#7{Blink.AtomShell.Electron})() at ./event.jl:68

(the error happens after I control-C... seems like there was an infinite wait on the read(::TCPSocket, ::Type{UInt8})

Reloaded notebook's PlotlyJS doesn't work

Once every five notebooks or so (OSX, Julia 0.4.5, using Plots.jl), the notebook gets in a broken state, such that when I reload it, all PlotlyJS plots have disappeared, and won't come back even after restarting the notebook. The only cure is to 1. Clear all outputs, 2. Save the notebook, 3. Refresh the page. I used to have almost exactly the same problem with Bokeh in python (except that Bokeh was at least printing a red Javascript error adding output! message), but it didn't happen as often. My guess is that this isn't Julia specific, but I wanted to get some feedback before posting upstream. Is this a known issue?

subplots

This one is tricky.

The python implementation is the 700 line function here

I certainly don't want something that complicated.

Save multiple plots to single html file (no subplots)

would it be possible to have a function that saves multiple plots to a single html file?
I know that subplots allow that in a way. However, I need a separate legend for each figure and when creating subplots, a single legend is instead generated for all the panels. Also, I haven't figured out how to configure the width and height of each panel when using subplots.

I think it would be useful to have a savepage function that just saves each plot individually. Something similar to the PdfPages matplotlib function.

Conflict with DataFrames.jl

Another issue that I am noticing is with interoperability with DataFrames. When I just execute using PlotlyJS everything's fine.

But if execute it after importing DataFrames or vice-versa. The screen get's filled with the following Warning messages.

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.2 (2015-12-06 21:47 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-apple-darwin13.4.0

julia> using DataFrames

julia> using PlotlyJS
WARNING: New definition 
    ./(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:55
is ambiguous with: 
    ./(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:285.
To fix, define 
    ./(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.
WARNING: New definition 
    +(AbstractArray, Images.AbstractImageDirect) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:20
is ambiguous with: 
    +(DataArrays.DataArray, AbstractArray) at /Users/datafig/.julia/v0.4/DataArrays/src/operators.jl:326.
To fix, define 
    +(DataArrays.DataArray, Images.AbstractImageDirect)
before the new definition.
WARNING: New definition 
    +(AbstractArray, Images.AbstractImageDirect) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:20
is ambiguous with: 
    +(DataArrays.AbstractDataArray, AbstractArray) at /Users/datafig/.julia/v0.4/DataArrays/src/operators.jl:349.
To fix, define 
    +(DataArrays.AbstractDataArray, Images.AbstractImageDirect)
before the new definition.
WARNING: New definition 
    .==(Images.AbstractImageDirect{Bool, N<:Any}, AbstractArray{Bool, N<:Any}) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:181
is ambiguous with: 
    .==(AbstractArray{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:330.
To fix, define 
    .==(Images.AbstractImageDirect{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}})
before the new definition.
WARNING: New definition 
    .==(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:182
is ambiguous with: 
    .==(AbstractArray{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:330.
To fix, define 
    .==(Images.AbstractImageDirect{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}})
before the new definition.
WARNING: New definition 
    .==(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:182
is ambiguous with: 
    .==(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:285.
To fix, define 
    .==(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.
WARNING: New definition 
    .<(Images.AbstractImageDirect{Bool, N<:Any}, AbstractArray{Bool, N<:Any}) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:177
is ambiguous with: 
    .<(AbstractArray{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:330.
To fix, define 
    .<(Images.AbstractImageDirect{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}})
before the new definition.
WARNING: New definition 
    .<(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:178
is ambiguous with: 
    .<(AbstractArray{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:330.
To fix, define 
    .<(Images.AbstractImageDirect{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}})
before the new definition.
WARNING: New definition 
    .<(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:178
is ambiguous with: 
    .<(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:285.
To fix, define 
    .<(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.
WARNING: New definition 
    -(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:35
is ambiguous with: 
    -(AbstractArray, DataArrays.DataArray) at /Users/datafig/.julia/v0.4/DataArrays/src/operators.jl:326.
To fix, define 
    -(Images.AbstractImageDirect, DataArrays.DataArray)
before the new definition.
WARNING: New definition 
    -(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:35
is ambiguous with: 
    -(AbstractArray, DataArrays.AbstractDataArray) at /Users/datafig/.julia/v0.4/DataArrays/src/operators.jl:349.
To fix, define 
    -(Images.AbstractImageDirect, DataArrays.AbstractDataArray)
before the new definition.
WARNING: New definition 
    -(AbstractArray, Images.AbstractImageDirect) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:37
is ambiguous with: 
    -(DataArrays.DataArray, AbstractArray) at /Users/datafig/.julia/v0.4/DataArrays/src/operators.jl:326.
To fix, define 
    -(DataArrays.DataArray, Images.AbstractImageDirect)
before the new definition.
WARNING: New definition 
    -(AbstractArray, Images.AbstractImageDirect) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:37
is ambiguous with: 
    -(DataArrays.AbstractDataArray, AbstractArray) at /Users/datafig/.julia/v0.4/DataArrays/src/operators.jl:349.
To fix, define 
    -(DataArrays.AbstractDataArray, Images.AbstractImageDirect)
before the new definition.
WARNING: New definition 
    .>(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:179
is ambiguous with: 
    .>(AbstractArray{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:330.
To fix, define 
    .>(Images.AbstractImageDirect{Bool, N<:Any}, Union{DataArrays.DataArray{Bool, N<:Any}, DataArrays.PooledDataArray{Bool, R<:Integer, N<:Any}})
before the new definition.
WARNING: New definition 
    .>(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:179
is ambiguous with: 
    .>(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:285.
To fix, define 
    .>(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.
WARNING: New definition 
    .*(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:51
is ambiguous with: 
    .*(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}, AbstractArray...) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:295.
To fix, define 
    .*(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.
WARNING: New definition 
    .*(AbstractArray, Images.AbstractImageDirect) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:52
is ambiguous with: 
    .*(Union{DataArrays.PooledDataArray, DataArrays.DataArray}, AbstractArray...) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:295.
To fix, define 
    .*(Union{DataArrays.PooledDataArray, DataArrays.DataArray}, Images.AbstractImageDirect)
before the new definition.
WARNING: New definition 
    .-(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:40
is ambiguous with: 
    .-(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:285.
To fix, define 
    .-(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.
WARNING: New definition 
    .+(Images.AbstractImageDirect, AbstractArray) at /Users/datafig/.julia/v0.4/Images/src/algorithms.jl:22
is ambiguous with: 
    .+(AbstractArray, Union{DataArrays.PooledDataArray, DataArrays.DataArray}, AbstractArray...) at /Users/datafig/.julia/v0.4/DataArrays/src/broadcast.jl:297.
To fix, define 
    .+(Images.AbstractImageDirect, Union{DataArrays.PooledDataArray, DataArrays.DataArray})
before the new definition.

Error when saving as pdf using Electron Display

Hi,

I am checking out PlotlyJS.jl and was trying to run a simple test to save a plot as PDF. Looking at the docs, I tried the following

using PlotlyJS
using Blink
p1 = PlotlyJS.Plot(scatter(;y=randn(3)))
PlotlyJS.savefig_imagemagick(sp::ElectronPlot, "test.pdf")

ERROR: LoadError: UndefVarError: sp not defined

How can I fix this ?

Thanks
Ajay

Plot, plot, [plots] and docs

I noticed today that the docs are slightly out of sync with the way the latest tagged version works.

p1 = Plot(scatter(;y=randn(3)))
p2 = Plot(histogram(;x=randn(50), nbinsx=4))
p3 = Plot(scatter(;y=cumsum(randn(12)), name="Random Walk"))
[p1 p2]

produces text output, while

p1 = plot(scatter(;y=randn(3)))
p2 = plot(histogram(;x=randn(50), nbinsx=4))
p3 = plot(scatter(;y=cumsum(randn(12)), name="Random Walk"))
[p1 p2]

or

p1 = Plot(scatter(;y=randn(3)))
p2 = Plot(histogram(;x=randn(50), nbinsx=4))
p3 = Plot(scatter(;y=cumsum(randn(12)), name="Random Walk"))
plot([p1 p2])

displays the plots.

It might also be worth mentioning how to programatically construct arrays of plots. For example

plots = [
    plot(histogram2d(;x=p[:x], y=p[:y]))
    for p in groupby(df, :category)
]

creates a Array{PlotlyJS.SyncPlot{PlotlyJS.JupyterDisplay},1} which renders as text, rather than a PlotlyJS.SyncPlot{PlotlyJS.JupyterDisplay} (the type of [p1 p2]). However, it can be made to display by calling

vcat(plots...)

I can submit a PR to try to clear this up later this week if no one beats me to it.

Background not set?

When I do this:

using ExamplePlots; test_examples(:plotly, 13)

it brings up a browser window and the plot looks correct (tan background). But if I do the same for the PlotlyJS backend, the background is white:

using ExamplePlots; test_examples(:plotlyjs, 13)

Any ideas why they would be different? It should be the same JSON.

Hook into plotly events

This is definitely possible.

We need to decide on an API.

It might require changes to blink to pass data back and forth for a callback

Error when plotting in IJulia notebooks

I have a fresh install of Julia in a Mac and I have been trying to use the plotly library in the IJulia notebooks but it is not working. The issue is similar to https://github.com/Keno/GraphViz.jl/issues/11 but I couldn't find a solution.

I didn't install Jupyter beforehand so I'm using Miniconda. I got the plots working on the REPL with Blink but so far nothing on the notebooks. Here is what I have:

using Plots; plotly()
p = plot(rand(10), c=:red, m=(20,:green))

[Plots.jl] Initializing backend: plotly
MethodError: `_writemime` has no method matching _writemime(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::MIME{symbol("image/svg+xml")}, ::Plots.Plot{Plots.PlotlyBackend})
Closest candidates are:
  _writemime(::IO, ::MIME{symbol("image/svg+xml")}, !Matched::Plots.Plot{Plots.PyPlotBackend})
  _writemime(::IO, !Matched::MIME{symbol("image/png")}, ::Plots.Plot{Plots.PlotlyBackend})
  _writemime(::IO, !Matched::MIME{symbol("text/html")}, ::Plots.Plot{Plots.PlotlyBackend})
  ...

 in writemime at /Users/pedrosilva/.julia/v0.4/Plots/src/output.jl:150
 in writemime at /Users/pedrosilva/.julia/v0.4/Plots/src/output.jl:140
 in writemime at multimedia.jl:43
 in sprint at iostream.jl:206
 in display_dict at /Users/pedrosilva/.julia/v0.4/Plots/src/output.jl:189

Using with Hydrogen?

Is there any known way to use this with Hydrogen? Plots appears as zero-size divs at the moment although the plotly.js code is successfully injected into the div:

image

    window.PLOTLYENV=window.PLOTLYENV || {};
    window.PLOTLYENV.BASE_URL="https://plot.ly";
    require(['plotly'], function(Plotly) {
        Plotly.newPlot('c8a0a161-fc86-4455-95c8-3e7755ec5533', [{"type":"scatter","y":[0,2,3,5],"x":[1,2,3,4],"fill":"tozeroy"},{"type":"scatter","y":[3,5,1,7],"x":[1,2,3,4],"fill":"tonexty"}],  {"margin":{"r":50,"l":50,"b":50,"t":60}}, {showLink: false});

    });

One error does appear in Atom's js console (details here):

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-JcP1jIzEcYyg9SEbIMaZiK06NuPMRfPxz5nmE1EGXEM='), or a nonce ('nonce-...') is required to enable inline execution.
(anonymous function) @ result-view.coffee:138
kernel.coffee:217 shell message: Message {idents: Array[0], header: Object, parent_header: Object, metadata: Object, content: Object…}

I'll start looking into this, but opening this issue in case someone else has already figured this out.

Also: Discovering this package has been the highlight of my week. Thanks!

Save and edit plot in cloud

The second item in the top menu "save and edit plot in cloud" doesn't really upload the plot generated with PlotlyJS to the Plot.ly server, it only opens their default plot editor. The upload "to the cloud" used to work earlier and I found it quite convenient, as I could make the plot with PlotlyJS locally, which is fast. Once I was satisfied with the plot, I would upload it to Plotly, to share with co-workers, and to do further minor editing interactively in the browser (e.g. when the journal required changes of the axis labels, like a different font).

After signing into plot.ly manually one time from the Electron browser, their plot editor shows that I'm signed in, but the PlotlyJS generated data are still not uploaded.

LaTeX integration

Just so you have the satisfaction of closing an issue when this is done.

Wishlist

This issue here to serve as a public wishlist for things people would like to see in the next release of PlotlyJS.jl. Essentially this is supposed to be a list of all the things you'd like to have/see in your ideal plotting package. This could be new feature suggestions or API wishes or anything else you can think of (though we can't promise everything will be implemented).

I'm going to copy the quantecon team here because we have some plans to push the library forward for QE usage, but contributions from anyone are absolutely welcome!

cc: @jstac, @cc7768, @mmcky, @oyamad, @albep, @vgregory757, @albop, @thomassargent30, @ZacCranko, @szokeb87, @danielcsaba

PlotlyJS doesn't work with Interact

PlotlyJS doesn't work with the @manipulate macro.

using Interact
@manipulate for i = 1:10
    PlotlyJS.plot()
end

gives an error:

Not implemented (yet). Use Electron frontend to save figures

REPL doc system

We should integrate with the Julia doc system. I had two ideas for this:

  1. Hook into @doc do provide plain text help at the REPL. The way I see that going is that we populate the help on the fly using the plotly-schema.json file that is the source of this page: https://plot.ly/javascript/reference/. What I had in mind was ?scatter would print the main text describing the scatter trace and then list out all the attributes. The user could then do ?scatter.attribute_name to get the specific help entry for that attribute
  2. Provide a more interactive html-based help that is served in an electron window. This would use the same data, but present a more easily readable and navigatible version of the page I linked to above. I envision it as a mathematica style documentation system. As a start to making the linked to page more readable we could just throw every item into some collapsable HTML element so users just see a list of the 12ish traces at first and can click their way through to more detail as needed. Then they don’t get the monster wall of text that the attribute reference page is right now

Data Transfer Performance

I promised a little writeup on this so here goes.

Right now marshalling all data to decimal and back is going to be pretty expensive. In an ideal world the marshalling would just be (the equivalent of):

xs = Float64[1,2,3]
write(io, xs)
ys = reinterpret(Float64, read(io, 3*4))

In fact, you can probably make things even faster by converting the data to Float16 first. JS can actually support this via the newfangled typed array feature. I don't know of an interchange format that supports these kinds of byte arrays directly, but as luck would have it there's a msgpack implementation which adds it on as an extension.

With a little bit of hacking on MsgPack.jl it should be straightforward to use buffers to transfer numerical data to the frontend, which should make that transfer at least 10dB faster as well as reducing memory footprint.

One snag is that there's no general support for typed arrays in Plotly yet (plotly/plotly.js#860). This will mean converting the buffer to a JS array, which will negate the memory usage benefit but hopefully won't be too much of a performance hit.

Clean up design

This package is a bit tricky to design because we need to have both Julia and Plotly versions of a plot object.

The original goal was to have the Julia object be first class and simply have the plotly version be a "clone" of the Julia version that handles the view. I think that design was compromised, especially in the plotly.js api methods.

This issue is a place to brainstorm possible ways to clean up the design.

cc: @one-more-minute @tbreloff

Javascript error on package load with IJulia/Firefox

This doesn't happen with Chrome. After using PlotlyJS, I see one of the following errors, but functionality seems to be ok otherwise.

Plotly javascript loaded.
Javascript error adding output!
TypeError: Plotly.plot is not a function
See your browser Javascript console for more details.
Javascript error adding output!
TypeError: define is not a function
See your browser Javascript console for more details.
Plotly javascript loaded.

Rename to PlotlyJS.jl

To be consistent with ThreeJS.jl and set a naming convention for Julia interfaces with JS APIs.

Error updating package

Using Windows 10 and julia 0.5.0-rc3-0

           _

_ _ ()_ | A fresh approach to technical computing
() | () () | Documentation: http://docs.julialang.org
_ _ | | __ _ | Type "?help" for help.
| | | | | | |/ ` | |
| | |
| | | | (
| | | Version 0.5.0-rc3+0 (2016-08-22 23:43 UTC)
/ |_'|||__'| | Official http://julialang.org/ release
|__/ | x86_64-w64-mingw32

julia> Pkg.update("PlotlyJS")
INFO: Updating METADATA...
INFO: Updating cache of DataFrames...
INFO: Updating cache of DataFrames...
INFO: Computing changes...
INFO: Upgrading BufferedStreams: v0.1.6 => v0.2.0
INFO: Upgrading DataFrames: v0.8.1 => v0.8.2
INFO: Upgrading PlotlyJS: v0.3.3 => v0.4.1
INFO: Rolling back DataFrames from v0.8.2 to v0.8.1
INFO: Rolling back BufferedStreams from v0.2.0 to v0.1.6
ERROR: PlotlyJS: fetch failed to get commit d8a0369, please file an issue at https://github.com/spencerlyon2/PlotlyJS.jl/issues
in fetch(::Base.LibGit2.GitRepo, ::String, ::String) at .\pkg\write.jl:25
in #3 at .\pkg\write.jl:53 [inlined]
in with(::Base.Pkg.Write.##3#4{String,String}, ::Base.LibGit2.GitRepo) at .\libgit2\types.jl:638
in resolve(::Dict{String,Base.Pkg.Types.VersionSet}, ::Dict{String,Dict{VersionNumber,Base.Pkg.Types.Available}}, ::Dict{String,Tuple{VersionNumber,Bool}}, ::Dict{String,Base.Pkg.Types.Fixed}, ::Dict{String,VersionNumber}, ::Set{String}) at .\pkg\entry.jl:537
in update(::String, ::Set{String}) at .\pkg\entry.jl:458
in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}})() at .\pkg\dir.jl:31
in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}}, ::String) at .\file.jl:48
in #cd#1(::Array{Any,1}, ::Function, ::Function, ::String, ::Vararg{Any,N}) at .\pkg\dir.jl:31
in update(::String, ::Vararg{String,N}) at .\pkg\pkg.jl:210

julia>

ERROR: connect: connection refused (ECONNREFUSED)

I'm getting the following error in two different computers:

julia> using Plots; plotlyjs()
Plots.PlotlyJSBackend()

julia> plot(1:10, rand(10))
[Plots.jl] Initializing backend: plotlyjs
Error showing value of type Plots.Plot{Plots.PlotlyJSBackend}:
ERROR: connect: connection refused (ECONNREFUSED)
 in yieldto at ./task.jl:71
 in wait at ./task.jl:371
 in wait at ./task.jl:286
 in stream_wait at ./stream.jl:60
 in wait_connected at ./stream.jl:331
 in connect at socket.jl:669
 in try_connect at /home/diego/.julia/v0.4/Blink/src/AtomShell/process.jl:58
 in init at /home/diego/.julia/v0.4/Blink/src/AtomShell/process.jl:72
 in shell at /home/diego/.julia/v0.4/Blink/src/AtomShell/process.jl:110
 in get_window at /home/diego/.julia/v0.4/PlotlyJS/src/displays/electron.jl:30
 in get_window at /home/diego/.julia/v0.4/PlotlyJS/src/displays/electron.jl:23
 in display at /home/diego/.julia/v0.4/PlotlyJS/src/displays/electron.jl:47
 in display at /home/diego/.julia/v0.4/Plots/src/output.jl:114
 in display at REPL.jl:117
 [inlined code] from multimedia.jl:151
 in display at multimedia.jl:162
 in print_response at REPL.jl:134
 in print_response at REPL.jl:121
 in anonymous at REPL.jl:624
 in run_interface at ./LineEdit.jl:1610
 in run_frontend at ./REPL.jl:863
 in run_repl at ./REPL.jl:167
 in _start at ./client.jl:420

This one is:

julia> versioninfo(true)
Julia Version 0.4.1
Commit cbe1bee (2015-11-08 10:33 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5 CPU         750  @ 2.67GHz
  WORD_SIZE: 64
           Ubuntu 15.04
  uname: Linux 3.19.0-26-generic #28-Ubuntu SMP Tue Aug 11 14:16:32 UTC 2015 x86_64 x86_64
Memory: 11.725090026855469 GB (3030.91796875 MB free)
Uptime: 2.679364e6 sec
Load Avg:  0.134765625  0.2265625  0.1513671875
Intel(R) Core(TM) i5 CPU         750  @ 2.67GHz: 
       speed         user         nice          sys         idle          irq
#1  1599 MHz    7274174 s     387255 s     759019 s  257963316 s         10 s
#2  1333 MHz    7232676 s     387630 s     775130 s  258054140 s         11 s
#3  2667 MHz    6803630 s     387476 s     765098 s  258439281 s        130 s
#4  1199 MHz    7711733 s     245117 s     809228 s  257621608 s         85 s

  BLAS: libopenblas (NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: liblapack.so.3
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
Environment:
  TERM = xterm
  XDG_SESSION_PATH = /org/freedesktop/DisplayManager/Session0
  XDG_SEAT_PATH = /org/freedesktop/DisplayManager/Seat0
  DEFAULTS_PATH = /usr/share/gconf/ubuntu.default.path
  PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/diego/.julia/v0.4/MIToS/scripts:/home/diego/Desktop/naccess
  MANDATORY_PATH = /usr/share/gconf/ubuntu.mandatory.path
  HOME = /home/diego
  COMPIZ_BIN_PATH = /usr/bin/

Package Directory: /home/diego/.julia/v0.4
48 required packages:
 - ArgParse                      0.3.0+             master
 - Atom                          0.4.1
 - BiomolecularStructures        0.0.1
 - Blink                         0.3.4
 - Bokeh                         0.2.0
 - Bootstrap                     0.3.3
 - Cairo                         0.2.31
 - DataFrames                    0.7.0
 - DataFramesMeta                0.1.1
 - Example                       0.4.1
 - FixedSizeArrays               0.0.10
 - GLFW                          1.1.2
 - GLM                           0.5.0
 - Gadfly                        0.4.2              fdb02ed4 (dirty)
 - GadflyDiff                    0.0.1
 - Hinton                        0.1.1
 - HttpParser                    0.1.1
 - HypothesisTests               0.2.10+            master
 - IJulia                        1.1.9
 - ImageMagick                   0.1.4
 - Immerse                       0.0.11
 - IndexedArrays                 0.1.0
 - Interact                      0.3.1
 - Jewel                         1.0.8
 - KernelDensity                 0.1.2
 - KernelEstimator               0.1.7
 - MIToS                         1.0.0+             master
 - Merly                         0.0.1
 - Mustache                      0.0.14
 - NLopt                         0.3.1
 - NetworkViz                    0.0.2
 - NullableArrays                0.0.2
 - PairwiseListMatrices          0.3.0+             master
 - Patchwork                     0.2.2
 - PlotlyJS                      0.1.4              master
 - Plots                         0.5.4
 - PyCall                        1.4.0
 - PyPlot                        2.1.1
 - Qwt                           0.0.1
 - RCall                         0.4.0
 - RDatasets                     0.1.2
 - ROCAnalysis                   0.0.1
 - Roots                         0.1.26
 - SmoothingKernels              0.0.0
 - UnicodePlots                  0.1.3
 - Vega                          0.6.5
 - VoronoiDelaunay               0.0.1
 - Winston                       0.11.13
119 additional packages:
 - ArrayViews                    0.6.4
 - AutoHashEquals                0.0.9
 - Benchmark                     0.1.0
 - Benchmarks                    0.0.0-             master (unregistered)
 - BinDeps                       0.3.21
 - BioSeq                        0.4.0
 - Blosc                         0.1.4
 - BufferedStreams               0.0.3
 - Calculus                      0.1.14
 - Clustering                    0.5.0
 - CodeTools                     0.3.0
 - Codecs                        0.1.5
 - ColorBrewer                   0.3.0
 - ColorTypes                    0.2.2
 - ColorVectorSpace              0.1.2
 - Colors                        0.6.3
 - Combinatorics                 0.2.0
 - Compat                        0.7.13
 - Compose                       0.4.2
 - ComposeDiff                   0.0.1
 - Conda                         0.1.9
 - Contour                       0.1.0
 - Cubature                      1.0.10
 - CurveFit                      0.1.0
 - DThree                        0.0.0-             master (unregistered)
 - DataArrays                    0.2.20
 - DataStructures                0.4.3
 - Dates                         0.4.4
 - Distances                     0.3.0
 - Distributions                 0.8.10
 - Docile                        0.5.23
 - DualNumbers                   0.2.2
 - FactCheck                     0.4.2
 - FastaIO                       0.1.4
 - FileIO                        0.0.4
 - FixedPointNumbers             0.1.2
 - Formatting                    0.1.5
 - ForwardDiff                   0.1.6
 - FreeType                      1.0.3
 - FunctionalCollections         0.1.3
 - GLAbstraction                 0.0.11             master
 - GLVisualize                   0.0.7              master
 - GLWindow                      0.1.1
 - GZip                          0.2.18
 - GeometricalPredicates         0.0.4
 - GeometryTypes                 0.1.4
 - GraphLayout                   0.3.1
 - GraphVisualize                0.0.0-             master (unregistered)
 - Graphics                      0.1.3
 - Grid                          0.4.0
 - Gtk                           0.9.3
 - GtkUtilities                  0.0.8
 - HDF5                          0.5.8
 - Hexagons                      0.0.4
 - Hiccup                        0.0.2
 - HttpCommon                    0.2.4
 - HttpServer                    0.1.5
 - Images                        0.5.3
 - ImmutableArrays               0.0.11
 - IniFile                       0.2.5
 - Iterators                     0.1.9
 - JLD                           0.5.9
 - JSON                          0.5.0
 - JuMP                          0.12.2
 - Judo                          0.0.0-             mdjl (unregistered)
 - JuliaParser                   0.6.4
 - LNR                           0.0.2
 - LaTeXStrings                  0.1.6
 - Lazy                          0.10.1
 - Lexicon                       0.1.18
 - Libz                          0.0.2
 - LightGraphs                   0.5.2
 - LightXML                      0.2.1
 - Loess                         0.0.6
 - MLPlots                       0.0.0-             master (unregistered)
 - MacroTools                    0.3.0
 - MathProgBase                  0.4.3
 - MbedTLS                       0.2.1
 - Measures                      0.0.2
 - Media                         0.1.2
 - MeshIO                        0.0.4
 - ModernGL                      0.0.7
 - Mux                           0.2.0
 - NaNMath                       0.2.1
 - Nettle                        0.2.2
 - NoveltyColors                 0.1.0
 - NumericFuns                   0.2.4
 - Optim                         0.4.4
 - PDMats                        0.4.1
 - Packing                       0.0.4
 - ParserCombinator              1.7.8
 - Polynomials                   0.0.5
 - Quaternions                   0.1.0
 - Reactive                      0.3.2
 - Reexport                      0.0.3
 - Requests                      0.3.6
 - Requires                      0.2.2
 - ReverseDiffSparse             0.5.5
 - SHA                           0.1.2
 - SIUnits                       0.0.6
 - Showoff                       0.0.6
 - SignedDistanceFields          0.0.1
 - SimpleStats                   0.0.0-             master (unregistered)
 - SortingAlgorithms             0.0.6
 - StatsBase                     0.8.0
 - StatsFuns                     0.2.0
 - TexExtensions                 0.0.3
 - TextWrap                      0.1.5
 - ThreeJS                       0.2.1
 - Tk                            0.3.7
 - URIParser                     0.1.3
 - WebSockets                    0.1.2
 - WoodburyMatrices              0.1.5
 - XMLDict                       0.0.8
 - YAML                          0.1.10
 - Yeppp                         0.0.10
 - ZMQ                           0.3.1
 - Zlib                          0.1.12
 - mdjl                          0.0.0-             master (unregistered)

Resize plot when electron window is resized

I'm on Windows. It would be great if the plot size would adjust as I resize the window where it is shown, so that the plot always uses the maximum available window space.

My use case is just the electron output, from the julia command line (i.e. no IJulia or anything like that).

Float32 arrays don't plot reliably on 0.5.0

It looks like Julia 0.5 changes the way that single-precision floating-point numbers are displayed in scientific notation. Instead of 3.05e-5 now it's 3.05f-5. Looks like if any of these show up in the data it hoses the display:

arr = Float32[-0.00735474, 3.05176f-5, 0.00769043]
plot(scatter(y=arr))

causes jupyter to say:

Javascript error adding output!
SyntaxError: Invalid or unexpected token
See your browser Javascript console for more details.

Related:
JuliaIO/JSON.jl#163
JuliaLang/julia#17720
JuliaLang/julia#18053
JuliaLang/julia#18682

Seems that it should be fixed in master, but hopefully it'll be backported to the next 0.5.x release. This probably shouldn't be worked-around in PlotlyJS, but I wanted to file the issue here in case somebody else came looking for an explanation of the error message.

IJulia comm

We've recently merged in some functionality that let's us have tighter communication with javascript in the notebook. These are the main things that have happened to enable this:

  • When we start up in the notebook we now load up a javascript file that prepares the javascript console in the browser where the notebook is running to receive messages from PlotlyJS.jl
  • On the javascript side, we have implemented two different evaluation targets for a jupyter-plotlyjs.jl comm:
    1. One that simply sends javascript to be evaluated
    2. A second one that executes the passed javascript, resolves any promises that were returned when the js was evaluated, and then sends the data back to Julia. (the sending happens here)
  • On the Julia side we now have one comm per JupyterDisplay. Really this means one comm per displayed figure. This comm will allow us to tap into those two targets we defined in the javascript file and send code to the javascript console to be evaluated.
    • This is initialized here
    • We then define two julia functions, one for each of the two targets. They are here

Now, what the status?

We have great Julia => javascript communication. This is evident in how well PlotlyJS.jl works inside an @manipulate call using Interact.jl.

What isn't working is getting data to go javascript => julia. Because plotly.js is async and uses promises in almost all functions, we need to do things async on the Julia side also.

To make this work, I've added a field cond::Condition on JupyterDisplay. This is the Condition from Base and it will allow us to notify when data is ready and it will allow us to wait until it is ready.

The issue we're facing now is that the on_msg callback we attach to each comm never seems to be called. To verify this I added these lines that simply create a file in the User's home directory when the callback is called. This file never appears.

I've tried a few things and haven't yet figured out what the hang up is. My assumption was that calling comm.send in the javascript would trigger comm.on_msg to be called in the Julia -- but that doesn't seem to happen.

Any ideas for why this is happening would be great.

cc @tbreloff

Error showing Plot

julia> import Plotlyjs; p = Plotlyjs.Plot(Plotlyjs.scatter(x=[],y=[],mode="markers"))
data: [
  "scatter with fields mode, x, and y"
]

layout: "layout with no fields"



julia> show(p)
ERROR (unhandled task failure): ArgumentError: cannot convert NULL to string
 in on_header_value at /home/tom/.julia/v0.4/HttpServer/src/RequestParser.jl:60
ERROR: JS load timed out
 in yieldto at ./task.jl:71
 in wait at ./task.jl:371
 in wait at ./task.jl:286
 in wait at /home/tom/.julia/v0.4/Blink/src/rpc/callbacks.jl:8
 in loadjs! at /home/tom/.julia/v0.4/Blink/src/content/api.jl:31
 in load! at /home/tom/.julia/v0.4/Blink/src/content/api.jl:43
 in show at /home/tom/.julia/v0.4/Plotlyjs/src/display.jl:53

Have display not duplicate plots in windows

Right now the main display function looks like this:

function Base.display(p::Plot)
    w = get_window(p)
    Blink.load!(w, _js_path)
    @js w begin
        @var thediv = document.createElement("div")
        thediv.id = $(string(p.divid));
        document.body.appendChild(thediv);
        Plotly.newPlot(thediv, $(p.data),  $(p.layout), d("showLink"=> false))
    end
    show(p)
end

This will create a new div with the same id each time the plot is re-displayed -- causing copies of the plot to show up in the window.

We need some logic here that says create the div if it doesn't exist, or just grab the existing one.

Anyone have any ideas?

cc: @one-more-minute

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.