Download file was broken. Encoding issue, dcc.Download

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)

The code looks syntactically wrong. I believe the correct syntax would be,

dcc.send_data_frame(df.to_csv, “mydf.csv”, encoding=“utf-8”, index=False)

I don’t have any experience with Korea language formatting though, so I am not sure if these changes will resolve that issue.

oh!! thanks a lot!

before I got your advice,
I change the code csv → excel (from plotly dash example code.)
I solved the issue,
however it is not enough to fast… I will try your code!

have a nice day!!!