Hello Everyone!
I just tried to add an additional dropdown bar for the year and when I did, the error: TypeError: init() takes from 1 to 2 positional arguments but 3 were given, popped up. Please advise or provide resources, thank you.
Sample Code:
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv(
“pulse.csv”
)
group_options = df[“Group”].unique()
year_options =df[“Year”].unique()
app = dash.Dash()
app.layout = html.Div([
html.H2(“Pulse Analysis Report”),
html.Div(
[
dcc.Dropdown(
id=“Group”,
options=[{
‘label’: i,
‘value’: i
} for i in group_options],
multi=True,
value=‘All Groups’),
],
[
dcc.Dropdown(
id="Year",
options=[{
'label' : i,
'value' : i,
} for i in year_options],
multi=True,
value='All Years'),
],
style={'width': '25%',
**'display': 'inline-block'}),**
dcc.Graph(id='funnel-graph'),
])
@app.callback(
dash.dependencies.Output(‘funnel-graph’, ‘figure’),
[dash.dependencies.Input(‘Group’, ‘value’)])
def update_graph(Group):
if Group == “All Groups”:
df_plot = df.copy()
else:
df_plot = df[df[‘Group’] == Group]
pv = pd.pivot_table(
df_plot,
index=['Question'],
columns=["Response"],
values=['Percentage'],
aggfunc='mean',
fill_value=0)
trace1 = go.Bar(x=pv.index, y=pv[('Percentage', 'Skipped')], name='skipped')
trace2 = go.Bar(x=pv.index, y=pv[('Percentage', 'Neutral')], name='neutral')
trace3 = go.Bar(x=pv.index, y=pv[('Percentage', 'Agree')], name='agree')
trace4 = go.Bar(x=pv.index, y=pv[('Percentage', 'Disagree')], name='disagree')
trace5 = go.Bar(x=pv.index, y=pv[('Percentage', 'Strongly_Disagree')], name=' strongly_disagree')
trace6 = go.Bar(x=pv.index, y=pv[('Percentage', 'Strongly_Agree')], name='strongly_agree')
return {
'data': [trace1, trace2, trace3, trace4, trace5, trace6],
'layout':
go.Layout(
title='Pulse Analysis for {}'.format(Group),
barmode='stack')
}
if name == ‘main’:
app.run_server(debug=True)
Please see the line with the double asterisks. This is where the issue is occurring and I’m unsure of how to resolve it.