-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Helper functions #144
Helper functions #144
Conversation
src/components_utils/express.jl
Outdated
callback!(app, Output("download", "data"), Input("download-btn", "n_clicks"), prevent_initial_call = true) do n_clicks | ||
return dcc_send_bytes("df.arr") do io | ||
Arrow.write(io, df) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This form where the first arg to dcc_send_bytes
is a function - it's a bit more cumbersome and confusing than the Python version that looks like
@app.callback(Output("download", "data"), Input("btn", "n_clicks"))
def func(n_clicks):
return dcx.send_data_frame(df.to_csv, "mydf.csv")
The Python one is already a little unintuitive - I wish pandas would have just allowed df.to_csv
to output a string if called with no buffer or file path - but at least you don't have to explicitly create a new function referencing an io
that you don't care about. I think if I were using this I'd prefer to just write it out myself:
callback!(app, Output("download", "data"), Input("download-btn", "n_clicks"), prevent_initial_call = true) do n_clicks
io = IOBuffer()
Arrow.write(io, df)
return dcc_send_bytes(take!(io), "df.arr")
More characters but the same number of lines in total, and less to learn about this interface. Is there any other way we can make this cleaner? Are there other use cases where the function to be called as src(io)
is already defined, the way df.to_csv
is? If not I might suggest dropping the src::Function
form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dcc_send_bytes(take!(io), "df.arr")
is also already possible. (dcc_send_bytes(src::AbstractVector{UInt8}, filename; type = nothing)
)
The version with callback and io seemed convenient to me. However, if you think that it is confusing, then I can remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not make an analogue of send_data_frame
because this would lead to a direct dependence of Dash on DataFrames and all packages of a particular serialization (CSV, Arrow, etc.) and thus would mean the need for a release every time the version of these packages changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at 925744e i change dcc_send_bytes(src::Function, filename; type = nothing)
to dcc_send_bytes(writer::Function, data, filename; type = nothing)
so example above is now look like
return dcc_send_bytes(Arrow.write, df, "df.arr")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner! 🎉
src/components_utils/table_format.jl
Outdated
) | ||
return JSON3.write( | ||
( | ||
locale = deepcopy(f.locale), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why deepcopy
is needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right, it is superfluous here. Removed in cc7ebaf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 💃
Implementation of functions for working with the
dcc_download
component and an analogue of Python'sFormat
to help in formatting theDataTable