dash-pivottable
dash-pivottable copied to clipboard
Pivottable doesn't get updated in successive callbacks
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.
has this been solved?
+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?
Still no luck on this one? Encountering the same issue..
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.
Same issue here
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. :(
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.
@wittyfans could you explain it more or provide a code example?
@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(),
...
)
]
@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!