question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pivottable doesn't get updated in successive callbacks

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

10reactions
standard-outliercommented, Nov 7, 2020

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.

3reactions
tomdaniekcommented, Oct 26, 2021

@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(),
            ...
        )
    ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pivottable doesn't get updated in successive callbacks #10
This works: import dash import dash_html_components as html from dash.dependencies import Input, Output import dash_pivottable app = dash.
Read more >
Refresh PivotTable data - Microsoft Support
Manually refresh or update data in a PivotTable that's connected to an external data source to see changes that were made to that...
Read more >
Excel Pivot Table Refresh Steps and Fixes - Contextures
Refresh Multiple Pivot Caches. If there are two or more pivot tables in your workbook, based on different data sources, they won't all...
Read more >
Countif dax - Divadonna.it
When it gets to the end of the table, DAX will go to the outer formula, SUMX, ... the number for less than...
Read more >
excel hierarchy tree from data - Ramozzi & Friends
getDataPath(data) callback to tell the grid the hierarchy for each row. 23 de set. To create hierarchies, you'll need to enable the Power...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found