plotly / dash-pivottable

react-pivottable in Dash
MIT License
192 stars 52 forks source link

The `vals` property is not updated when accessed through callback #38

Open Plug11 opened 3 years ago

Plug11 commented 3 years ago

Description

The vals property is not updated when accessed through a callback (unlike other properties such as cols and rows).

This would be really useful to maintain state between updates to the data of the pivot table. Currently, vals always has the original value.

Steps/Code to Reproduce

Run the following code and change the quantity being plotted from "Total Bill" to "Tips". The output vals quantity will not change and will continue to report "Total Bill".

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

from data import data

app = dash.Dash(__name__)
app.title = 'My Dash example'

app.layout = html.Div([
    dash_pivottable.PivotTable(
        id='table',
        data=data,
        cols=['Day of Week'],
        colOrder="key_a_to_z",
        rows=['Party Size'],
        rowOrder="key_a_to_z",
        rendererName="Grouped Column Chart",
        aggregatorName="Average",
        vals=["Total Bill"],
        valueFilter={'Day of Week': {'Thursday': False}}
    ),
    html.Div(
        id='output'
    )
])

@app.callback(Output('output', 'children'),
              [Input('table', 'cols'),
               Input('table', 'rows'),
               Input('table', 'rowOrder'),
               Input('table', 'colOrder'),
               Input('table', 'aggregatorName'),
               Input('table', 'rendererName'),
               Input('table', 'vals')])
def display_props(cols, rows, row_order, col_order, aggregator, renderer, vals):
    return [
        html.P(str(cols), id='columns'),
        html.P(str(rows), id='rows'),
        html.P(str(row_order), id='row_order'),
        html.P(str(col_order), id='col_order'),
        html.P(str(aggregator), id='aggregator'),
        html.P(str(renderer), id='renderer'),
        html.P(str(vals), id='vals'),
    ]

if __name__ == '__main__':
    app.run_server(debug=True)

Versions

Dash 1.19.0 Dash Core Components 1.1.2 Dash HTML Components 1.15.0 Dash Renderer 1.9.0 Dash Pivot Table 0.0.2

ika11ika commented 5 months ago

+1

noamgot commented 6 days ago

+1