Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Help with simple bar chart with callback

$
0
0

@nyc123 wrote:

Hello - Im having trouble with a very simple callback where I would like the months on the x axis and a count of each month for the y axis (and filtering by category in a dropdown)

I’m pretty new to dash/plotly so bare with me.

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div([

 html.Div([
    dcc.Dropdown(
        id='category-dropdown',
        options=[{'label': i, 'value': i} for i in categories],
        value='cars',
    )
], className='four columns'),


### for some reason I need to add text after dropdown otherwise it is hidden
html.H3(
    children='Categories by Month',
    style={
        'textAlign': 'center',
    }
),

html.Div([
    dcc.Graph(id='category-graph'),
], className='row')
])


@app.callback(
    Output('category-graph', 'figure'),
    [Input('category-dropdown', 'value')])
 def update_graph(category_dropdown_name):
dff = df[df['category' == category_dropdown_name]]

return {
    'data': [dict(
        x=dff['months'].unique(),
        y=dff['months'],  # .value_counts().sort_index().reindex(months, fill_value=0),
       # i would like to get a count for each month (i tried to do a value count which seems to work on a 
         normal graph but not in a callback

   type='bar',
    )]
}


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

Posts: 9

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6271

Latest Images

Trending Articles



Latest Images