galactic
galactic

Reputation: 17

Dash error : 'dash_core_components' has no attribute 'send dataframe'

In my dash I have a callback that create a pd.to_dict object that is stored with dcc.Store, in order to be used for further plots.

I am trying to create a download button to download this created data frame.

This is part of my code (removed other import or layout options) :

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)

But when running the app.py, I get 'dash_core_components' has no attribute 'send dataframe', even though it has it.

I have dash version 2.0.0.

Upvotes: 0

Views: 3323

Answers (1)

bas
bas

Reputation: 15722

I have dash version 2.0.0

Replace how you import dash core components from this

import dash_core_components as dcc

to this

from dash import dcc

As of Dash 2, the development of dash-core-components has been moved to the main Dash repo

quote source

Upvotes: 1

Related Questions