Hi
I have an imputo for csv, and whant to download it to json. Is this possible? How?
I pass from a drag n drop a csv, pass it to json, but can’t download it? (or don’t know how).
How can I download it?
Hi
I have an imputo for csv, and whant to download it to json. Is this possible? How?
I pass from a drag n drop a csv, pass it to json, but can’t download it? (or don’t know how).
How can I download it?
Hello @topotaman,
It’s pretty straightforward, use this as an example:
from dash import Dash, dcc, html, Input, Output
import pandas as pd
app = Dash(__name__)
app.layout = html.Div(
[
html.Button("Download JSON", id="btn_json"),
dcc.Download(id="download-dataframe-json"),
]
)
df = pd.DataFrame({"a": [1, 2, 3, 4], "b": [2, 1, 5, 6], "c": ["x", "x", "y", "y"]})
@app.callback(
Output("download-dataframe-json", "data"),
Input("btn_json", "n_clicks"),
prevent_initial_call=True,
)
def func(n_clicks):
return dcc.send_data_frame(df.to_json, "mydf.json")
if __name__ == "__main__":
app.run_server(debug=True, port=8000)
Basically, pass your dataframe to the dcc.send_data_frame as json.
thanks! yeeeeeha!!