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

Add Plotly support #50

Closed
davidanthoff opened this issue Dec 2, 2019 · 6 comments
Closed

Add Plotly support #50

davidanthoff opened this issue Dec 2, 2019 · 6 comments
Assignees

Comments

@davidanthoff
Copy link
Member

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
Copy link
Contributor

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

@davidanthoff
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

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
Copy link
Contributor

sglyon commented Jan 21, 2020

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
Copy link
Member Author

This works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants