Skip to content

Commit 925744e

Browse files
committed
change send_ functions signature
1 parent dda4dd3 commit 925744e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/components_utils/express.jl

+10-13
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ end
1717

1818
"""
1919
dcc_send_bytes(src::AbstractVector{UInt8}, filename; type = nothing)
20-
dcc_send_bytes(src::Function, filename; type = nothing)
20+
dcc_send_bytes(writer::Function, data, filename; type = nothing)
2121
2222
Convert vector of bytes into the format expected by the Download component.
23+
`writer` function must have signature `(io::IO, data)`
2324
2425
# Examples
2526
@@ -37,9 +38,7 @@ using DataFrames, Arrow
3738
...
3839
df = DataFrame(...)
3940
callback!(app, Output("download", "data"), Input("download-btn", "n_clicks"), prevent_initial_call = true) do n_clicks
40-
return dcc_send_bytes("df.arr") do io
41-
Arrow.write(io, df)
42-
end
41+
return dcc_send_bytes(Arrow.write, df, "df.arr")
4342
end
4443
```
4544
"""
@@ -53,18 +52,18 @@ function dcc_send_bytes(src::AbstractVector{UInt8}, filename; type = nothing)
5352
)
5453
end
5554

56-
function dcc_send_bytes(src::Function, filename; type = nothing)
55+
function dcc_send_bytes(writer::Function, data, filename; type = nothing)
5756
io = IOBuffer()
58-
src(io)
57+
writer(io, data)
5958
return dcc_send_bytes(take!(io), filename, type = type)
6059
end
6160

6261
"""
6362
dcc_send_data(src::AbstractString, filename; type = nothing)
64-
dcc_send_data(src::Function, filename; type = nothing)
63+
dcc_send_data(writer::Function, data, filename; type = nothing)
6564
6665
Convert string into the format expected by the Download component.
67-
`src` is a string or function that takes a single argument - io and writes data to it
66+
`writer` function must have signature `(io::IO, data)`
6867
6968
# Examples
7069
@@ -82,9 +81,7 @@ using DataFrames, CSV
8281
...
8382
df = DataFrame(...)
8483
callback!(app, Output("download", "data"), Input("download-btn", "n_clicks"), prevent_initial_call = true) do n_clicks
85-
return dcc_send_string("df.csv") do io
86-
CSV.write(io, df)
87-
end
84+
return dcc_send_string(CSV.write, df, "df.csv")
8885
end
8986
```
9087
"""
@@ -98,8 +95,8 @@ function dcc_send_string(src::AbstractString, filename; type = nothing)
9895
)
9996
end
10097

101-
function dcc_send_string(src::Function, filename; type = nothing)
98+
function dcc_send_string(writer::Function, data, filename; type = nothing)
10299
io = IOBuffer()
103-
src(io)
100+
writer(io, data)
104101
return dcc_send_string(String(take!(io)), filename, type = type)
105102
end

0 commit comments

Comments
 (0)