Open KeithWM opened 1 month ago
Bug confirmed. Thanks!
This is related to Dash.jl's switch to JSON3.
Callbacks should now expect JSON3.Array
and JSON3.Object
as arguments, which are immutable.
So, to append value a value to a list (like in Editable Table example), we must use a standard Julia Vector type instead.
I would recommand rewriting the problematic callback as:
callback!(app,
Output("editing-columns", "columns"),
Input("editing-columns-button", "n_clicks"),
State("editing-columns-name", "value"),
State("editing-columns", "columns")
) do n_clicks, value, existing_columns
return if n_clicks > 0 && value != ""
new_column = Dict(
"id" => value, "name" => value,
"renamable" => true, "deletable" => true
)
vcat(Dict.(existing_columns), new_column)
else
existing_columns
end
end
Unfortunately, I do not have acces to the Plotly documentation source code, so someone at Plotly will need to make the update.
Thanks again @KeithWM for bringing this up!
Thanks for confirming the bug and pointing me towards a solution. I'm trying to work out how to do this for adding a new row, but I'm having a hard time running the code in such a way that I can quickly retrigger the behaviour. What is the recommended way to do this? Is there some way to for the callback to be initiated from the REPL without having to manually refresh the served HTML page and click the button?
This has done the trick:
callback!(app,
Output("adding-rows-table", "data"),
Input("adding-rows-button", "n_clicks"),
State("adding-rows-table", "data"),
State("adding-rows-table", "columns")
) do n_clicks, existing_data, columns
return if n_clicks > 0
new_row = Dict(c.id => "" for c in columns)
return vcat(Dict.(existing_data), new_row)
else
return existing_data
end
end
But I would still appreciate some help in improving my way-of-working. :-)
Maybe try something like:
# main.jl
function addrow_callback(n_clicks, existing_data, columns)
return if n_clicks > 0
new_row = Dict(c.id => "" for c in columns)
return vcat(Dict.(existing_data), new_row)
else
return existing_data
end
end
callback!(addrow_callback, app,
Output("adding-rows-table", "data"),
Input("adding-rows-button", "n_clicks"),
State("adding-rows-table", "data"),
State("adding-rows-table", "columns"))
and then in the REPL or in a test file
import JSON3
json3ify(x) = JSON3.read(JSON3.write(x))
dash_callback_call(cb, args...) = cb(json3ify.(args)...)
dash_callback_call(addrow_callback, 1, [#= ... =#], [#= ... =#])
Thanks. I think that works (after changing the final call to dash_callback_call(addrow_callback, 1, [#= ... =#], [#= ... =#])
, with a comma instead of the first open paren.) I can also obtain the proper arguments via app.layout.children[1].data
.
(after changing the final call
Yep, sorry! I edited my previous comment with the fix.
The examples that include adding rows or columns in https://dash.plotly.com/julia/datatable/editable do not appear to work when copy-pasted locally.
The error I see is
I believe the line
push!(rows, Dict(c.id => "" for c in columns))
may be at fault for trying topush!
a dictionary onto a JSON3 object, which I presume worked previously, but is no longer supported. I would delve deeper into the issue, but I find it hard to debug the issue as I do not know how to create the objects inside thecallback!
function from the REPL.