简体   繁体   中英

Pie chart wont generate - dash/plotly

I'm trying to create a Pie chart in plotly. There are no errors, but it won't show up.

I've created a date range picker which works and provides the results I need, but I haven't tried it with the pie chart just yet, as I want to test the chart with some arbitrary numbers first. Can you help me get it running please? Below is the code:

app = dash.Dash()

app.layout = html.Div([

    dcc.DatePickerRange(
        id='my-date-picker-range',
        min_date_allowed=dt(2019, 4, 1),
        max_date_allowed=dt(2019, 6, 30),
        #initial_visible_month=dt(2019, 4, 1),
        end_date=dt(2019, 4, 2),
        start_date=dt(2019, 4, 1)
    ),
    html.Div(id='output-container-date-picker-range')
])


@app.callback(
    dash.dependencies.Output('output-container-date-picker-range', 'children'),
    [dash.dependencies.Input('my-date-picker-range', 'start_date'),
     dash.dependencies.Input('my-date-picker-range', 'end_date')]) 

def update_output(start_date, end_date):

    #some calculations

    return{
            'data': [go.Pie(labels=['Navy','Sand'], values=[50,50],
                             marker={'colors': ['#EF963B','C93277']},textinfo='label')
                    ],

            'layout': go.Layout(
                title='distribution',
                margin={'l': 100, 'r': 10},
                legend={'x': 0, 'y': 1.5},

            )
        }

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

Your callback right now returns a dict into the children of an html.Div component, so you're missing a dcc.Graph somewhere. Try return dcc.Graph({...}) instead of return {...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM