support dcc.send_file and dcc.send_data_frame
kafisatz opened this issue · comments
This is a cross post from https://discourse.julialang.org/t/dash-jl-send-file-or-send-data-frame/63499
Is it correct, that dcc.send_data_frame and dcc.send_file are not supported yet.
I am trying to reproduce these examples in Julia
https://dash.plotly.com/dash-core-components/download
dcc.send_file seems most critical to me.
turns out that for a DataFrame
-> csv file, there is quite a simple workaround
callback!(app,
Output("download-modelresult","data"),
Input("btn-download-model-results", "n_clicks"),
prevent_initial_call = true
) do n_clicks
df = DataFrames.DataFrame(a=rand(3),b=["a","b","xx"])
csvrowwriteriterator = CSV.RowWriter(df)
str = join(collect(csvrowwriteriterator))
return Dict("filename"=>"miha.csv","content"=>str ,"base64"=>false)
end
similarly for any file on disk, this works for me
#send file from disk
file_from_disk = raw"c:\temp\temp.7z"
#file_from_disk = raw"c:\temp\png1.png"
rf = read(file_from_disk)
io = IOBuffer()
iob64_encode = Base64.Base64EncodePipe(io)
write(iob64_encode,rf)
close(iob64_encode)
str = String(take!(io))
#String(Base64.base64decode(str))
fn = splitdir(file_from_disk)[2]
return Dict("filename"=>fn,"content"=>str,"base64"=>true)