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?