17
17
18
18
"""
19
19
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)
21
21
22
22
Convert vector of bytes into the format expected by the Download component.
23
+ `writer` function must have signature `(io::IO, data)`
23
24
24
25
# Examples
25
26
@@ -37,9 +38,7 @@ using DataFrames, Arrow
37
38
...
38
39
df = DataFrame(...)
39
40
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")
43
42
end
44
43
```
45
44
"""
@@ -53,18 +52,18 @@ function dcc_send_bytes(src::AbstractVector{UInt8}, filename; type = nothing)
53
52
)
54
53
end
55
54
56
- function dcc_send_bytes (src :: Function , filename; type = nothing )
55
+ function dcc_send_bytes (writer :: Function , data , filename; type = nothing )
57
56
io = IOBuffer ()
58
- src (io)
57
+ writer (io, data )
59
58
return dcc_send_bytes (take! (io), filename, type = type)
60
59
end
61
60
62
61
"""
63
62
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)
65
64
66
65
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)`
68
67
69
68
# Examples
70
69
@@ -82,9 +81,7 @@ using DataFrames, CSV
82
81
...
83
82
df = DataFrame(...)
84
83
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")
88
85
end
89
86
```
90
87
"""
@@ -98,8 +95,8 @@ function dcc_send_string(src::AbstractString, filename; type = nothing)
98
95
)
99
96
end
100
97
101
- function dcc_send_string (src :: Function , filename; type = nothing )
98
+ function dcc_send_string (writer :: Function , data , filename; type = nothing )
102
99
io = IOBuffer ()
103
- src (io)
100
+ writer (io, data )
104
101
return dcc_send_string (String (take! (io)), filename, type = type)
105
102
end
0 commit comments