Hello guys,
Can someone please help me understand what I am missing in my code below. I get an error “TypeError: a number is required” during the callback. I suspect its the values or labels but I cannot figure it out.
@app.callback(Output('sentiment-pie', 'figure'),
Input('pie-update','interval'))
def update_pie_chart(n):
df = pd.read_sql("SELECT sentiment FROM messages" ,conn)
df['pos'] = count(df[df['sentiment']>= 0.05])
df['neg'] = count(df[df['sentiment']<= -0.05])
print(type(df['pos'].values()))
labels=['positive','negative']
values = pd.DataFrame(df['pos'],df['neg'])
colors = ['#007F25', '#800000']
trace = go.Pie(labels=labels,values=values,
hoverinfo='label+percent', textinfo='value',
textfont=dict(size=20, color=colors['text']),
marker=dict(colors=colors,
line=dict(color=colors['background'])))
return {"data":[trace],'layout' : go.Layout(
title='Positive vs Negative sentiment for',
font={'color':colors['text']},
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
showlegend=True)}