Dash error : 'dash_core_components' has no attribute 'send dataframe'
Dash error : 'dash_core_components' has no attribute 'send dataframe'
在我的破折号中,我有一个回调创建了一个 pd.to_dict
对象,该对象与 dcc.Store
一起存储,以便用于进一步的绘图。
我正在尝试创建一个下载按钮来下载这个创建的数据框。
这是我的代码的一部分(删除了其他导入或布局选项):
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__)
app.layout = html.Div([
html.H2('Enter a text query'),
dcc.Store(id='memory'),
html.Button('Submit', id='button', n_clicks=0),
html.Button("Download CSV", id="csv"),
dcc.Download(id="download-df")])
@app.callback(
Output('memory', 'data'),
[Input('button', 'n_clicks')],
[State('searchterm', 'value')]
)
def create_df_func(n_clicks, searchterm):
#some code to create df
return df.to_dict(orient='records')
@app.callback(
Output('download-df', 'data'),
[Input('csv', 'n_clicks')],
[State('memory', 'data')],
prevent_initial_call=True,
)
def download_csv(n_clicks, df):
data = pd.DataFrame(df)
return dcc.send_data_frame(data.to_csv, "mydf.csv")
if __name__ == '__main__':
app.run_server(debug=True)
但是当 运行 和 app.py 时,我得到 'dash_core_components' has no attribute 'send dataframe'
,即使它有。
我有 dash 版本 2.0.0。
I have dash version 2.0.0
替换您从中导入破折号核心组件的方式
import dash_core_components as dcc
至此
from dash import dcc
As of Dash 2, the development of dash-core-components has been moved to the main Dash repo
在我的破折号中,我有一个回调创建了一个 pd.to_dict
对象,该对象与 dcc.Store
一起存储,以便用于进一步的绘图。
我正在尝试创建一个下载按钮来下载这个创建的数据框。
这是我的代码的一部分(删除了其他导入或布局选项):
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__)
app.layout = html.Div([
html.H2('Enter a text query'),
dcc.Store(id='memory'),
html.Button('Submit', id='button', n_clicks=0),
html.Button("Download CSV", id="csv"),
dcc.Download(id="download-df")])
@app.callback(
Output('memory', 'data'),
[Input('button', 'n_clicks')],
[State('searchterm', 'value')]
)
def create_df_func(n_clicks, searchterm):
#some code to create df
return df.to_dict(orient='records')
@app.callback(
Output('download-df', 'data'),
[Input('csv', 'n_clicks')],
[State('memory', 'data')],
prevent_initial_call=True,
)
def download_csv(n_clicks, df):
data = pd.DataFrame(df)
return dcc.send_data_frame(data.to_csv, "mydf.csv")
if __name__ == '__main__':
app.run_server(debug=True)
但是当 运行 和 app.py 时,我得到 'dash_core_components' has no attribute 'send dataframe'
,即使它有。
我有 dash 版本 2.0.0。
I have dash version 2.0.0
替换您从中导入破折号核心组件的方式
import dash_core_components as dcc
至此
from dash import dcc
As of Dash 2, the development of dash-core-components has been moved to the main Dash repo