Error loading dependencies on piechart

Hi,
whenever I add the code downbelow to my program I get “error loading dependencies”. The terminal seems to show nothing new.
Would anyone happen to know what causes it?

                html.Div(className='four columns', style={}, children=[
                    dcc.Graph(
                        id='pie-chart',
                        figure={
                            'data': [1, 2],
                            'labels': ['a', 'b']
                        }
                    )
                ]),

The Graph component builds Plotly graphs. You can’t just feed it Python data structures and have it work it out – you need to tell it what type of charts you want to build. Do you want a histogram or a scatter plot etc? So the data attribute of the figure dict needs to be a list of plotly.graph_objs objects. You then feed each of those objects your raw data. See the docs for examples.

@verluci - In particular, to create a piechart, try something like this:

dcc.Graph(
    id='pie-chart',
    figure={
         'data': [{
                'type': 'pie',
                'labels': ['a', 'b'],
                'values: [1, 2]
         }]
    }
)

Here are more examples of pie charts: https://plot.ly/python/pie-charts/

You can adapt those examples to the dcc.Graph element by placing the array like [trace] inside the 'data' key of the figure attribute.

For example, the “Styled Pie Chart” example here: https://plot.ly/python/pie-charts/#styled-pie-chart could be adapted in dash like:


import plotly.plotly as py
import plotly.graph_objs as go

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500,2500,1053,500]
colors = ['#FEBFB3', '#E1396C', '#96D38C', '#D0F9B1']

trace = go.Pie(labels=labels, values=values,
               hoverinfo='label+percent', textinfo='value', 
               textfont=dict(size=20),
               marker=dict(colors=colors, 
                           line=dict(color='#000000', width=2)))

dcc.Graph(
    id='pie',
    figure={
        'data': [trace]
    }
)

Thanks for the replies! I realize now what a stupid mistake I made, haha. It had been a long day and I was having some trouble with the piechart before (different errors) so when I tried to start anew later at home and got this I just figured I’d go to the forums. I was aware I should have included the go.Pie chart especially, but I just forgot.
Still, thanks for the answers! Super helpful and I’ll try again and see if I can make it work this time.

1 Like