# Python - plotly - dash\_pivottable.PivotTable - callbacks

**URL:** <https://community.plotly.com/t/python-plotly-dash-pivottable-pivottable-callbacks/34044>\
**Category:** 📊 Plotly Python\
**Created:** [January 23, 2020, 2:14pm UTC](https://community.plotly.com/t/python-plotly-dash-pivottable-pivottable-callbacks/34044 "2020-01-23T14:14:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LZS](https://avatars.discourse-cdn.com/v4/letter/l/ecd19e/32.png) [@LZS](https://community.plotly.com/u/LZS)\
**Post date:** [January 23, 2020, 2:14pm UTC](https://community.plotly.com/t/python-plotly-dash-pivottable-pivottable-callbacks/34044/1 "2020-01-23T14:14:59Z")

</div>

When I create a Pivot table in my dashboard, it works fine. But when I want to use a callback to change the data, it doesn’t work. The Pivot table just doesn’t change. I have also tried to put the whole pivot in the callback, but that doesn’t help either. Am I doing something wrong?

### create app

app = dash.Dash( **name** )

app.scripts.config.serve\_locally = True  
app.css.config.serve\_locally = True

app.title = ‘LZS Dash Pivot table’

### app layout

app.layout = html.Div(  
id=‘bigbox’,  
children=[

```
    # dropdown with all users
    dcc.Dropdown(
        id='users-dropdown',
        options=dictionary_list,
        value='HIDDEN FOR PRIVACY REASONS'
    ),                
    
    # pivot table
    html.Div(
        id='first_pivot',
        children=[
            dash_pivottable.PivotTable(
                id='table',
                data=my_list,
                cols=['day_of_month', 'hour_of_day','clid', 'dst'],
                colOrder="key_a_to_z",
                rows=['IDS', 'dst_country'],
                rowOrder="key_a_to_z",
                rendererName="Stacked Column Chart",
                aggregatorName="Count",
                vals=["day_of_month"]
            )]
)

```

])

# I TRIED TWO THINGS

### CALLBACK DATA

@app.callback(  
[  
dash.dependencies.Output(‘table’, ‘data’ ),  
],  
[  
dash.dependencies.Input(component\_id=‘users-dropdown’, component\_property=‘value’)  
])

def load\_file(file):

```
print(str(file))

# load file
my_df = pd.read_csv(str(file), low_memory=False)

# create list of lists   
my_list = my_df.values.tolist()
my_headers = list(my_df.columns) 
my_list.insert(0,my_headers)  

# return data
return [my_list]

```

# AND

### CALLBACK DATA

@app.callback(  
[  
dash.dependencies.Output(‘first\_pivot’, ‘children’),  
],  
[  
dash.dependencies.Input(component\_id=‘users-dropdown’, component\_property=‘value’)  
])

def load\_file(file):

```
print(str(file))

# load file
my_df = pd.read_csv(str(file), low_memory=False)

# add & rename columns
my_df['time'] = pd.to_datetime(my_df['time'])
my_df['day_of_week'] = my_df['time'].dt.day_name()
my_df['day_of_month'] = my_df['time'].dt.day
my_df['hour_of_day'] = my_df['time'].dt.hour
my_df['minute_of_hour'] = my_df['time'].dt.minute
my_df['round_minute_of_hour'] = round(my_df['minute_of_hour'],-1)
my_df['round_premium'] = round(my_df['UserAuth.whiteLister.voteAggregator.PremiumNumberProfiler.result'],1)
my_df=my_df.rename(columns={"UserAuth.whiteLister.voteAggregator.StrictDoubleCall.result": "StrictDoubleCall", "UserAuth.whiteLister.custom.dst": "dst_country"})
my_df['dst_country']= my_df['dst_country'].fillna('Unknown')

# create list of lists   
my_list = my_df.values.tolist()
my_headers = list(my_df.columns) 
my_list.insert(0,my_headers)  

# return pivot
return [dash_pivottable.PivotTable(
            id='table',
            data=my_list,
            cols=['day_of_month', 'hour_of_day','clid', 'dst'],
            colOrder="key_a_to_z",
            rows=['IDS', 'dst_country'],
            rowOrder="key_a_to_z",
            rendererName="Stacked Column Chart",
            aggregatorName="Count",
            vals=["day_of_month"]
        )]
```

---

<div class="post-metadata">

**Author:** ![Numan](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@Numan](https://community.plotly.com/u/Numan)\
**Post date:** [July 18, 2020, 7:32pm UTC](https://community.plotly.com/t/python-plotly-dash-pivottable-pivottable-callbacks/34044/2 "2020-07-18T19:32:12Z")

</div>

I got the same issue, is it resolved?

---

<div class="post-metadata">

**Author:** ![piterdias](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@piterdias](https://community.plotly.com/u/piterdias)\
**Post date:** [April 28, 2021, 5:00pm UTC](https://community.plotly.com/t/python-plotly-dash-pivottable-pivottable-callbacks/34044/3 "2021-04-28T17:00:42Z")

</div>

Not sure if someone has a better solution, but returning dash\_pivottable.PivotTable with a random id triggers a data update.  
Is there a better way?
