JuliaPlots / PlotlyJS.jl

Julia library for plotting with plotly.js
Other
418 stars 77 forks source link

no method `get(::String, ...)` for PlotlyJS on dataframe #409

Closed mzaffalon closed 3 years ago

mzaffalon commented 3 years ago

I am following along the Dash tutorial for Julia and I have an error on the following piece of code

using DataFrames, PlotlyBase, UrlDownload

df1 = DataFrame(urldownload("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv"))

Plot(df1[df1.year .== 2002, :],
                          Layout(xaxis_type = "log",
                                 xaxis_title = "GDP Per Capita",
                                 yaxis_title = "Life Expectancy",
                                 legend_x = 0,
                                 legend_y = 1,
                                 hovermode = "closest",
                                 transition_duration = 500),
                          x = :gdpPercap,
                          y = :lifeExp,
                          text = :country,
                          group = :continent,
                          mode = "markers",
                          marker_size = 15,
                          marker_line_color = "white")
ERROR: MethodError: no method matching get(::String, ::Symbol, ::Dict{Any, Any})
Closest candidates are:
  get(::Union{Tables.AbstractColumns, Tables.AbstractRow}, ::Union{Integer, Symbol}, ::Any) at C:\Users\michele.zaffalon\.julia\packages\Tables\E99hk\src\Tables.jl:185
  get(::Union{Shape, GenericTrace, Layout, PlotlyBase.PlotlyAttribute, PlotlyFrame}, ::Symbol, ::Any) at C:\Users\michele.zaffalon\.julia\packages\PlotlyBase\S8uAJ\src\traces_layouts.jl:236
  get(::DataStructures.DefaultDict, ::Any...) at C:\Users\michele.zaffalon\.julia\packages\DataStructures\nBjdy\src\delegate.jl:21
  ...
Stacktrace:
 [1] getindex(gt::Layout{Dict{Symbol, Any}}, k1::Symbol, k2::Symbol, k3::Symbol)
   @ PlotlyBase C:\Users\michele.zaffalon\.julia\packages\PlotlyBase\S8uAJ\src\traces_layouts.jl:401
 [2] getindex(gt::Layout{Dict{Symbol, Any}}, key::String)
   @ PlotlyBase C:\Users\michele.zaffalon\.julia\packages\PlotlyBase\S8uAJ\src\traces_layouts.jl:377
 [3] getindex(gt::Layout{Dict{Symbol, Any}}, key::Symbol)
   @ PlotlyBase C:\Users\michele.zaffalon\.julia\packages\PlotlyBase\S8uAJ\src\traces_layouts.jl:387
 [4] setifempty!(hf::Layout{Dict{Symbol, Any}}, key::Symbol, value::Symbol)
   @ PlotlyBase C:\Users\michele.zaffalon\.julia\packages\PlotlyBase\S8uAJ\src\traces_layouts.jl:224
 [5] Plot(df::DataFrame, l::Layout{Dict{Symbol, Any}}; category_orders::Missing, labels::Missing, facet_row::Missing, facet_col::Missing, group::Symbol, symbol::Missing, color::Missing, line_dash::Missing, kw::Base.Iterators.Pairs{Symbol, Any, NTuple{6, Symbol}, NamedTuple{(:x, :y, :text, :mode, :marker_size, :marker_line_color), Tuple{Symbol, Symbol, Symbol, String, Int64, String}}})
   @ PlotlyBase C:\Users\michele.zaffalon\.julia\packages\PlotlyBase\S8uAJ\src\dataframes_api.jl:346
 [6] top-level scope
   @ REPL[3]:1

Pkg.status

(@v1.6) pkg> st
      Status `C:\Users\michele.zaffalon\.julia\environments\v1.6\Project.toml`
  ...
  [a93c6f00] DataFrames v1.2.2
  ...
  [a03496cd] PlotlyBase v0.8.5
  [f0f68f2c] PlotlyJS v0.18.3
  ...
  [856ac37a] UrlDownload v1.0.0
  ...

and versioninfo

Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
empet commented 3 years ago

My feeling is that who edited this example pasted the code and mixed data and layout. It is missing chart type (scatter, bar,...).

mzaffalon commented 3 years ago

There is indeed a method Plot(df, layout; style, kargs...) described in the manual.

sglyon commented 3 years ago

Thanks for opening! THis is a bug I will fix up today

BTW new dash julia docs are in the works and will be released soon, so stay tuned

mzaffalon commented 3 years ago

Thank you for fixing it quickly!