How to trigger call back function in dash_pivottable

Viewed 424

I am trying to define a callback function that is called when a cell of my pivot table is called.

My code is below.

Unfortunately test_function test function is only called once and not each time a cell is clicked as i want.

Is this possible and what changes do i need to make to achieve this?

import jupyter_dash as dash
from dash import html, Input, Output, State
import dash_pivottable

app = dash.JupyterDash(__name__)
server = app.server

app.layout = html.Div(
    [dash_pivottable.PivotTable(
        id='table',
        data=[
            ['Animal', 'Count', 'Location'],
            ['Zebra', 5, 'SF Zoo'],
            ['Tiger', 3, 'SF Zoo'],
            ['Zebra', 2, 'LA Zoo'],
            ['Tiger', 4, 'LA Zoo'],
        ],
        
        cols=["Animal"],
        rows=["Location"],
        vals=["Count"],
        

    ),
    
    html.Div(id='click-data', style={'whiteSpace': 'pre-wrap'})]
)



@app.callback(
    Output('click-data', component_property="children"),
    [Input('table','clickData'),
     Input("table", "hoverData"),
    Input("table", component_property="cols"),
    Input("table", component_property="rows"),
    Input("table", component_property="rowOrder"),
    Input("table", component_property="colOrder"),
    Input("table", component_property="aggregatorName"),
    Input("table", component_property="rendererName")]
)
def test_function(clickData,  hoverData, cols, rows, row_order, col_order, aggregator, renderer):
    print("hello")
    print(rows)
    print(cols)
    print(hoverData)
    return clickData




if __name__ == "__main__":
    app.run_server(mode='inline')
0 Answers
Related