The app is running on a server (remote host). A client can access the server remotely. dcc.Upload()
can take input from the client’s machine. After processing the client’s input, is there a function to save the processed data back to the client-side?
For a better idea about what I mean, please see the # TODO
block in the simple example below:
import base64, io
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
import pandas as pd
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Upload(
id='csv',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files')
]),
),
html.Br(),
html.Div(id='page-content')
])
@app.callback(Output('page-content','children'),
[Input('csv','contents')])
def update_dropdown(raw_contents):
if not raw_contents:
raise PreventUpdate
_, contents = raw_contents.split(',')
decoded = base64.b64decode(contents)
df = pd.read_csv(io.StringIO(decoded.decode('utf-8')))
# TODO
# I can only save on the server
# df.to_csv('/save/on/client/side.csv')
return 'File loaded, saving ...'
if __name__=='__main__':
app.run_server(debug=True, port=8050, host='localhost')