Black Lives Matter. Please consider donating to Black Girls Code today.

Creating Pivot Tables in dashboard?

Is it not possible to create pivot tables to be used with the dashboard?

I keep getting “TypeError (repr(o) + is not JSON serializable”. I was really hoping to create dynamic pivot tables to be used in my dashboard. Is there an other alternative that can be done to get dynamic pivot tables?

I was able to do Pivot Table for one of my company projects. What I did was using pandas DataFrame, specifically this method:
Arguments to that would be Dash inputs (buttons, select, etc). Output would be a table.

That’s what I’m doing and I still get the same error.

df = pd.read_csv(r'C:\...\Classification.csv')
pt = pd.DataFrame.pivot_table(df, index=['Classification'], values=['After Tax'], aggfunc='count', fill_value=0)

all_options = {
	'Category 1': ['Report 1', 'Report 2', 'Report 3'],
	'Category 2': ['Report A', 'Report B', 'Report C'],
	'Category 3': ['Report X', 'Report Y', 'Report Z']

app.layout = html.Div(style={'backgroundColor': colors['background']},
	children=[html.H1('AWS O2C Metrics', style={'textAlign': 'center'}),
    html.Label('Please make a selection'),
        options=[{'label': k, 'value': k} for k in all_options.keys()] 

It displays both the drop downs but whenever I put in the pt, it causes me to get the TypeErrror Not JSON serializable error. Is anything wrong in the above code?

You are trying to display a dataframe directly inside the app.layout. This isn’t possible as a DataFrame is not a string, number, list, or dash component. You need to convert the dataframe into a dash component before displaying it. See for one way to display a table, and the table example in the dash user guide at for another example.

This makes a lot of sense - thanks a lot for the help Chris!

I’m very new to python (and programming) so just want to thank you for Dash as it let’s me accomplish exactly what I need through just 1 programming language and not having to learn html/js/etc…

PS: Is there engineering support (paid) for Dash? only mentions Plotly2 and other products but doesn’t mention Dash at all. Would purchasing support for Plotly2 also give support for Dash or does it not exist at all for Dash currently?