Skip to content

Pivottable doesn't get updated in successive callbacks #10

@WestXu

Description

@WestXu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions