Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Dash Pie Subplots

Hi,
I would like to subplot two Pie Charts
Let’s says

app = dash.Dash()
app.scripts.config.serve_locally = True
temp = pd.DataFrame({"code": ["AAR","BBC","DDT","PPL","PPL", "AAR","BBC","DDT"], "target":[1,0,1,0,1,0,1,0]})

app.layout = html.Div(children=[
    dcc.Input(id='top-x-activities', value='5', type='text'),
    dcc.Graph(id='top-x-activities-pie')
])

@app.callback(
    dash.dependencies.Output('top-x-activities-pie', 'figure'),
    [dash.dependencies.Input('top-x-activities', 'value')])

def update_figure(top_n):
    traces = tools.make_subplots(rows=1, cols=2, specs=[[{}], [{}]])
    for i in temp["target"].unique():
        condition = (temp['target'] == 0)
        labels = temp.loc[condition, "code"].value_counts().head(int(top_n)).index.tolist()
        labels.append("Others")
        values = temp.loc[condition, "dst_famille_ape"].value_counts().head(int(top_n)).tolist()
        values.append(temp.shape[0] - np.sum(values))
        traces.append_trace(go.Pie(labels=labels, values=values,
                        hoverinfo='label+percent', textinfo='value', 
                        textfont=dict(size=20),
                        marker=dict(line=dict(color='#000000', width=2))), 1, i+1)

return {
    'data': traces,
    'layout': go.Layout(
              title = "Top " + top_n
    )
}

app.css.append_css({
    'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})

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

The error is Exception: The number of rows in ‘specs’ must be equal to ‘rows’

This should be rows=2, cols=1, or you should change your specs to be specs=[[{}, {}]]