Unexpected end of JSON input with PlotlyJS

The following code work well with PlotlyBase.jl.

using DataFrames, PlotlyBase, PlotlyJS
using Dash, DashHtmlComponents, DashCoreComponents
using JSON


MMM = DataFrame(GRADE = ["M", "M", "F"], LOTE = ["L1","L2","L3"], freq = [[1,2,3],[1,2,4],[1,3,4]], visc=[[5,8,9], [2,4,8],[3,6,9]])

available_indicators = unique(MMM[!, "GRADE"])


p1 =  Plot(scatter(x=MMM[1,:freq],y=MMM[1,:visc]))


app = dash()

app.layout = html_div() do
    


dcc_graph(id = "graph-1"),



    html_div(
        children = [
            html_label("grade", style=Dict("font-weight" => "bold")),

            dcc_dropdown(
                id = "grade1",
                options = [(label = i, value = i) for i in available_indicators],
                value = "M",
            ),
            html_label("batch", style=Dict("font-weight" => "bold")),
            dcc_dropdown(
                id = "lot",
            ),

        ],
        style = (width = "48%", display = "inline-block"),
    )
end



callback!(
    app,
    Output("lot", "options"),
    Input("grade1", "value"),
    
) do grade1_name
   
    MMn=filter(:GRADE => isequal(grade1_name), MMM)        #return part of the table with grade name

    return [(label = j, value = j) for j in unique(MMn[!, :LOTE])]

end


callback!(
    app,
    Output("lot", "value"),
    Input("lot", "options"),

) do available_options

    return available_options[1][:value]
    
end



callback!(
    app,
    Output("graph-1", "figure"),
    Input("lot", "value"),
    State("grade1", "value"),

) do lot_name, grade_nome
    
    Mn2=filter(:GRADE => isequal(grade_nome), MMM)
    Mn2=filter!(:LOTE => isequal(lot_name), Mn2)

    println(Mn2[1,:freq],Mn2[1,:visc])
   visi = scatter(x=Mn2[1,:freq],y=Mn2[1,:visc])

    return (
        Plot(visi)
    )

end


run_server(app, "0.0.0.0", 8050, debug=true) 

Then, if I use PlotlyJS.jl

using DataFrames, PlotlyBase, PlotlyJS
using Dash, DashHtmlComponents, DashCoreComponents
using JSON


MMM = DataFrame(GRADE = ["M", "M", "F"], LOTE = ["L1","L2","L3"], freq = [[1,2,3],[1,2,4],[1,3,4]], visc=[[5,8,9], [2,4,8],[3,6,9]])

available_indicators = unique(MMM[!, "GRADE"])


p1 =  Plot(scatter(x=MMM[1,:freq],y=MMM[1,:visc]))


app = dash()

app.layout = html_div() do
    


dcc_graph(id = "graph-1"),



    html_div(
        children = [
            html_label("grade", style=Dict("font-weight" => "bold")),

            dcc_dropdown(
                id = "grade1",
                options = [(label = i, value = i) for i in available_indicators],
                value = "M",
            ),
            html_label("batch", style=Dict("font-weight" => "bold")),
            dcc_dropdown(
                id = "lot",
            ),

        ],
        style = (width = "48%", display = "inline-block"),
    )
end



callback!(
    app,
    Output("lot", "options"),
    Input("grade1", "value"),
    
) do grade1_name
   
    MMn=filter(:GRADE => isequal(grade1_name), MMM)        #return part of the table with grade name

    return [(label = j, value = j) for j in unique(MMn[!, :LOTE])]

end


callback!(
    app,
    Output("lot", "value"),
    Input("lot", "options"),

) do available_options

    return available_options[1][:value]
    
end



callback!(
    app,
    Output("graph-1", "figure"),
    Input("lot", "value"),
    State("grade1", "value"),

) do lot_name, grade_nome
    
    Mn2=filter(:GRADE => isequal(grade_nome), MMM)
    Mn2=filter!(:LOTE => isequal(lot_name), Mn2)

    println(Mn2[1,:freq],Mn2[1,:visc])
   visi = scatter(x=Mn2[1,:freq],y=Mn2[1,:visc])

    return (
        plot(visi)
    )

end


run_server(app, "0.0.0.0", 8050, debug=true)

it returns an error β€œUnexpected end of JSON input” β€œCallback error updating graph-1.figure”

 Error: error handling request
β”‚   exception =
β”‚    StackOverflowError:
β”‚    Stacktrace:
β”‚         [1] (::JSON2.var"#3#4"{DataType})(x::Symbol)
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:11        
β”‚         [2] macro expansion
β”‚           @ C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:75 [inlined]    
β”‚         [3] write(io::IOBuffer, obj::WebIO.DOM; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:94        
β”‚         [4] write(io::IOBuffer, obj::WebIO.DOM)
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:94        
β”‚    --- the last 3 lines are repeated 3 more times ---
β”‚        [14] write(io::IOBuffer, obj::Vector{Any}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:39        
β”‚        [15] write(io::IOBuffer, obj::Vector{Any})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:35        
β”‚        [16] macro expansion
β”‚           @ C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:75 [inlined]    
β”‚        [17] write(io::IOBuffer, obj::Observables.Observable{Dict{Any, Any}}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:94        
β”‚        [18] write
β”‚           @ C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:94 [inlined]    
β”‚        [19] write(io::IOBuffer, obj::Tuple{Observables.Observable{Dict{Any, Any}}, Nothing}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})  
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:39        
β”‚        [20] write(io::IOBuffer, obj::Tuple{Observables.Observable{Dict{Any, Any}}, Nothing})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:35        
β”‚        [21] write(io::IOBuffer, obj::Dict{String, Tuple{Observables.AbstractObservable, Union{Nothing, Bool}}}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:24        
β”‚        [22] write(io::IOBuffer, obj::Dict{String, Tuple{Observables.AbstractObservable, Union{Nothing, Bool}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:17        
β”‚        [23] macro expansion
β”‚           @ C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:75 [inlined]    
β”‚        [24] write(io::IOBuffer, obj::WebIO.Scope; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:94        
β”‚        [25] write(io::IOBuffer, obj::WebIO.Scope)
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:94        
β”‚    --- the last 3 lines are repeated 1 more time ---
β”‚    --- the last 15 lines are repeated 2208 more times ---
β”‚     [33149] write(io::IOBuffer, obj::Dict{Symbol, Any}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:24        
β”‚     [33150] write(io::IOBuffer, obj::Dict{Symbol, Any})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:17        
β”‚    --- the last 2 lines are repeated 1 more time ---
β”‚     [33153] write(io::IOBuffer, obj::Dict{Symbol, Any}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:24        
β”‚     [33154] write
β”‚           @ C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:17 [inlined]    
β”‚     [33155] #write#5
β”‚           @ C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:14 [inlined]    
β”‚     [33156] write(obj::Dict{Symbol, Any})
β”‚           @ JSON2 C:\Users\jorgem63\.julia\packages\JSON2\ld4Kq\src\write.jl:14        
β”‚     [33157] process_callback(request::HTTP.Messages.Request, state::Dash.HandlerState) 
β”‚           @ Dash C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\handler\processors\callback.jl:72
β”‚     [33158] try_handle
β”‚           @ C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\router.jl:51 [inlined]
β”‚     [33159] try_handle(route::Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.StaticRoute, typeof(Dash.process_callback)}}, path::SubString{String}, request::HTTP.Messages.Request, args::Dash.HandlerState)
β”‚           @ Dash.HttpHelpers C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\router.jl:97
β”‚     [33160] _handle
β”‚           @ C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\router.jl:101 
[inlined]
β”‚     [33161] _handle (repeats 5 times)
β”‚           @ C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\router.jl:102 
[inlined]
β”‚     [33162] handle(route_tuple::Tuple{Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.StaticRoute, typeof(Dash.process_layout)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.StaticRoute, typeof(Dash.process_dependencies)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.StaticRoute, typeof(Dash.process_reload_hash)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.DynamicRoute{Tuple{Tuple{Int64, String}}, NamedTuple{(:path, :namespace), Tuple{Int64, Int64}}}, typeof(Dash.process_resource)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.DynamicRoute{Tuple{Tuple{Int64, String}}, NamedTuple{(:file_path,), Tuple{Int64}}}, typeof(Dash.process_assets)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.StaticRoute, typeof(Dash.process_callback)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.DynamicRoute{Tuple{}, NamedTuple{(), Tuple{}}}, typeof(Dash.process_index)}}, Dash.HttpHelpers.Route{Dash.HttpHelpers.RouteHandler{Dash.HttpHelpers.StaticRoute, typeof(Dash.process_index)}}}, path::SubString{String}, request::HTTP.Messages.Request, args::Dash.HandlerState)
β”‚           @ Dash.HttpHelpers C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\router.jl:112
β”‚     [33163] handle(router::Dash.HttpHelpers.Router, request::HTTP.Messages.Request, args::Dash.HandlerState)
β”‚           @ Dash.HttpHelpers C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\router.jl:129
β”‚     [33164] (::Dash.HttpHelpers.var"#1#2"{Dash.HttpHelpers.Router, Dash.HandlerState})(::HTTP.Messages.Request)
β”‚           @ Dash.HttpHelpers C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\handlers.jl:4
β”‚     [33165] handle
β”‚           @ C:\Users\jorgem63\.julia\packages\HTTP\D0FSE\src\Handlers.jl:254 [inlined] 
β”‚     [33166] (::Dash.HttpHelpers.var"#7#8"{Dash.var"#71#73"{Dash.DashApp}, HTTP.Handlers.RequestHandlerFunction{Dash.HttpHelpers.var"#1#2"{Dash.HttpHelpers.Router, Dash.HandlerState}}})(::HTTP.Messages.Request)
β”‚           @ Dash.HttpHelpers C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\handlers.jl:48
β”‚     [33167] handle
β”‚           @ C:\Users\jorgem63\.julia\packages\HTTP\D0FSE\src\Handlers.jl:254 [inlined] 
β”‚     [33168] (::Dash.HttpHelpers.var"#4#5"{Vector{String}, Int64, HTTP.Handlers.RequestHandlerFunction{Dash.HttpHelpers.var"#7#8"{Dash.var"#71#73"{Dash.DashApp}, HTTP.Handlers.RequestHandlerFunction{Dash.HttpHelpers.var"#1#2"{Dash.HttpHelpers.Router, Dash.HandlerState}}}}})(::HTTP.Messages.Request)
β”‚           @ Dash.HttpHelpers C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\HttpHelpers\handlers.jl:27
β”‚     [33169] handle
β”‚           @ C:\Users\jorgem63\.julia\packages\HTTP\D0FSE\src\Handlers.jl:254 [inlined] 
β”‚     [33170] handle(::HTTP.Handlers.RequestHandlerFunction{Dash.HttpHelpers.var"#4#5"{Vector{String}, Int64, HTTP.Handlers.RequestHandlerFunction{Dash.HttpHelpers.var"#7#8"{Dash.var"#71#73"{Dash.DashApp}, HTTP.Handlers.RequestHandlerFunction{Dash.HttpHelpers.var"#1#2"{Dash.HttpHelpers.Router, Dash.HandlerState}}}}}}, ::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
β”‚           @ HTTP.Handlers C:\Users\jorgem63\.julia\packages\HTTP\D0FSE\src\Handlers.jl:277
β”‚     [33171] #4
β”‚           @ C:\Users\jorgem63\.julia\packages\HTTP\D0FSE\src\Handlers.jl:346 [inlined] 
β”‚     [33172] macro expansion
β”‚           @ C:\Users\jorgem63\.julia\packages\HTTP\D0FSE\src\Servers.jl:413 [inlined]  
β”” @ Dash C:\Users\jorgem63\.julia\packages\Dash\66VCI\src\handler\make_handler.jl:110  

How to solve this? What is the problem?

Hi @jorge-jardim thanks for reaching out!

I just tried your example with the most recent versions of the related packages and couldn’t repeat your error.

The versions I have are:

  • Dash.jl: 0.1.6
  • PlotlyBase.jl: 0.8.16
  • PlotlyJS.jl: 0.8.17

Could you try updating your packages and repeating?

Thanks

Thank you, @sglyon. You are right; I was not using the most recent versions of those packages. Now, it works well.

P.S. ItΒ΄s also OK in Julia 1.7.0-rc1.