Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pivottable doesn't get updated in successive callbacks #10

Open
WestXu opened this issue Nov 1, 2019 · 10 comments · May be fixed by #47
Open

Pivottable doesn't get updated in successive callbacks #10

WestXu opened this issue Nov 1, 2019 · 10 comments · May be fixed by #47

Comments

@WestXu
Copy link

WestXu commented Nov 1, 2019

This works:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

import dash_pivottable

app = dash.Dash(__name__)

app.layout = html.Div(
    [html.Button("Rfresh", id="button"), html.Div(id="pivottable_div")]
)


@app.callback(Output("pivottable_div", "children"), [Input("button", "n_clicks")])
def refresh_pivottable(n_clicks):
    if n_clicks:
        print(n_clicks)
        return [
            html.Div(str(n_clicks)),
            dash_pivottable.PivotTable(data=[["a"], [n_clicks]], cols=["a"])
            if n_clicks % 2 == 1
            else "a",
        ]


if __name__ == "__main__":
    app.run_server(debug=False)

This doesn't:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

import dash_pivottable

app = dash.Dash(__name__)

app.layout = html.Div(
    [html.Button("Rfresh", id="button"), html.Div(id="pivottable_div")]
)


@app.callback(Output("pivottable_div", "children"), [Input("button", "n_clicks")])
def refresh_pivottable(n_clicks):
    if n_clicks:
        print(n_clicks)
        return [
            html.Div(str(n_clicks)),
            dash_pivottable.PivotTable(data=[["a"], [n_clicks]], cols=["a"])
            # if n_clicks % 2 == 1
            # else "a",
        ]


if __name__ == "__main__":
    app.run_server(debug=False)

The only difference of them is the 2 commented lines.

My environment:

windows7 64bit
python3.7 64bit
dash 1.4.1

Please run the cases to see the difference. Many thanks.

@futureplant
Copy link

has this been solved?

@ghost
Copy link

ghost commented Feb 4, 2020

+1, I am also running into this issue.

If I use a dash_table, it updates when the callback is fired after the first time. Same callback structure and everything for dash_pivottable and it does not update when the callback is fired.

Has anybody come up with a workaround?

@Qua111
Copy link

Qua111 commented Mar 4, 2020

Still no luck on this one? Encountering the same issue..

@abogaard
Copy link

abogaard commented Jun 17, 2020

I also had some trouble updating the pivot table properties though callbacks. You can hack it by placing the PT inside a dcc.Loading element, and make a secondary callback to a non data property (I used menuLimit) when data is changed, but its all pretty hacky.

@radupm
Copy link

radupm commented Oct 7, 2020

Same issue here

@standard-outlier
Copy link

Same issue, @abogaard Could you please give us an example code? I tried to put the PT inside a dcc.Loading, and fire the callback using same input with the data generator(Some dropdown selector to filter data or choose file), but it still doesn't work. :(

@standard-outlier
Copy link

Same issue, @abogaard Could you please give us an example code? I tried to put the PT inside a dcc.Loading, and fire the callback using same input with the data generator(Some dropdown selector to filter data or choose file), but it still doesn't work. :(

Update: My problem is caused by the table's ID, I generate every table with a random table id in callbacks solved my problem.

@adrienpacifico
Copy link

@wittyfans could you explain it more or provide a code example?

@tomvansanten
Copy link

@adrienpacifico I had the same problem with loading in contents from a file that is chosen by a dropdown. This solution works for me. I think @wittyfans did it with some random number generator but the main point seems to be to change the id.

from datetime import datetime

@app.callback(
    Output('pivottable_div', 'children'),
    Input('file-dropdown', 'value')
)
def update_output(value):
    # Do stuff to load data
    return [
        dash_pivottable.PivotTable(
            id="%s" % datetime.now(),
            ...
        )
    ]

AdrianIssott added a commit to AdrianIssott/dash-pivottable that referenced this issue Jul 7, 2022
AdrianIssott added a commit to AdrianIssott/dash-pivottable that referenced this issue Jul 7, 2022
@AdrianIssott AdrianIssott linked a pull request Jul 7, 2022 that will close this issue
6 tasks
@namnguyen8-tiki
Copy link

@adrienpacifico I had the same problem with loading in contents from a file that is chosen by a dropdown. This solution works for me. I think @wittyfans did it with some random number generator but the main point seems to be to change the id.

from datetime import datetime

@app.callback(
    Output('pivottable_div', 'children'),
    Input('file-dropdown', 'value')
)
def update_output(value):
    # Do stuff to load data
    return [
        dash_pivottable.PivotTable(
            id="%s" % datetime.now(),
            ...
        )
    ]

work like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants