queryverse / ElectronDisplay.jl

An Electron.jl based figure and table display.
Other
85 stars 17 forks source link

Add Plotly support #50

Closed davidanthoff closed 4 years ago

davidanthoff commented 4 years ago

We should move the plotly support into the gallery as well. I think there is a plotly react package, so hopefully that won't be too difficult. We can do this later, though.

TonyLianLong commented 4 years ago

How do we display a plot with Plotly and ElectronDisplay currently?

davidanthoff commented 4 years ago

My guess is that right now we fall back to SVG or PNG. In previous versions we had native support for plotly, i.e. we shipped the javascript plotly stuff in ElectronDisplay.jl, and supported a plotly MIME type, same story that we had for vega and vegalite. I think we should probably look whether there is a react plotly component that we can use in the same way that we use vega and vega-lite?

TonyLianLong commented 4 years ago

Yes, I have found a way to display graphs with Plotly. However, I need to know the syntax for Julia. So can you give me an example of Plotly in Julia? I tried the ones on the Plotly website but it could not be executed (https://plot.ly/julia/time-series/).


julia> using Plotly

julia> data = [
         [
           "x" => ["2013-10-04 22:23:00", "2013-11-04 22:23:00", "2013-12-04 22:23:00"],
           "y" => [1, 3, 6],
           "type" => "scatter"
         ]
       ]
1-element Array{Array{Pair{String,Any},1},1}:
 ["x" => ["2013-10-04 22:23:00", "2013-11-04 22:23:00", "2013-12-04 22:23:00"], "y" => [1, 3, 6], "type" => "scatter"]

julia> response = Plotly.plot(data, ["filename" => "date-axes", "fileopt" => "overwrite"])
ERROR: MethodError: no method matching Plot(::Array{Array{Pair{String,Any},1},1}, ::Array{Pair{String,String},1})
Closest candidates are:
  Plot(::AbstractArray{T,1}, ::AbstractArray{T,1} where T) where T<:Union{Dates.Date, Dates.DateTime, AbstractString, Number, Symbol} at /Users/tll/.julia/packages/PlotlyBase/80KwD/src/convenience_api.jl:20
  Plot(::AbstractArray{T,1}, ::AbstractArray{T,1} where T, ::Layout; kind, style, kwargs...) where T<:Union{Dates.Date, Dates.DateTime, AbstractString, Number, Symbol} at /Users/tll/.julia/packages/PlotlyBase/80KwD/src/convenience_api.jl:20
  Plot(::AbstractArray{T,1}, ::AbstractArray{T,2} where T) where T<:(AbstractArray{T,1} where T) at /Users/tll/.julia/packages/PlotlyBase/80KwD/src/convenience_api.jl:32
  ...
Stacktrace:
 [1] #plot#6(::Dict{Any,Any}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot), ::Array{Array{Pair{String,Any},1},1}, ::Vararg{Any,N} where N) at /Users/tll/.julia/packages/PlotlyJS/b9Efu/src/display.jl:145
 [2] plot(::Array{Array{Pair{String,Any},1},1}, ::Vararg{Any,N} where N) at /Users/tll/.julia/packages/PlotlyJS/b9Efu/src/display.jl:145
 [3] top-level scope at REPL[3]:1

julia> plot_url = response["url"]
ERROR: UndefVarError: response not defined
Stacktrace:
 [1] top-level scope at REPL[4]:1
davidanthoff commented 4 years ago

I think the correct package is PlotlyJS.jl.

I think in theory their plot type should just have support for the application/vnd.plotly.v1+json MIME type, and then everything should work. But I'm not sure whether that is actually so, at some point that package had a lot of non-standard stuff beyond the official Julia display stack story that I never really understood... @sglyon, any insights on the current state of things?

I think one can also use https://github.com/JuliaPlots/Plots.jl with the plotlyjs backend, and presumably that might also create a plot object that supports plotly MIME type, but I'm again not sure.

I would say we should try to use both of these packages. If they properly integrate via the plotly MIME type, great, and we'll keep the plotly support in here. If not, then I'm not sure we should try to work around that too much.

sglyon commented 4 years ago

Hey @davidanthoff thanks for brining me in here.

PlotlyJS.jl does implement the mimetype (and so does Plotly.jl -- the latter package reexports everything from the former and adds in connection to plot.ly cloud/apis)

My display integration was very wacky/non-standard, but has since been cleaned out. It should adhere to the Julia display stack now (I think?).

Let me know what else I can do to support plotly here

davidanthoff commented 4 years ago

This works now.