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"]
)]