hi ~ @@
I wanted to make a button for download file as .csv format.
the button worked well, however the file was broken. (I am Korean so my file has Korean + English + number data)
only korean language was broken.
I needed to set the encoding option… How should I do this?
I did like this,
return dcc.send_data_frame(df.to_csv(encoding=“utf-8”, index=False), “mydf.csv”) then,
I got the error = Attribute Error : ‘str’ object has no attribute ‘name’
this below code is the example code on the plotly web and I refer this.
from dash import Dash, dcc, html, Input, Output, callback
import pandas as pd
app = Dash(name)
app.layout = html.Div(
[
html.Button(“Download CSV”, id=“btn_csv”),
dcc.Download(id=“download-dataframe-csv”),
]
)
df = pd.DataFrame({“a”: [1, 2, 3, 4], “b”: [2, 1, 5, 6], “c”: [“x”, “x”, “y”, “y”]})
@callback(
Output(“download-dataframe-csv”, “data”),
Input(“btn_csv”, “n_clicks”),
prevent_initial_call=True,
)
def func(n_clicks):
return dcc.send_data_frame(df.to_csv, “mydf.csv”)
if name == “main”:
app.run(debug=True)