โœŠ๐Ÿฟ Black Lives Matter. Please consider donating to Black Girls Code today.
๐Ÿ‡ Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Can't create a sunburst because of the values

I want to create a sunburst from plotly express but it seems I have a problem in my values.
Indeed, nothing shows up when trying to plot. But when I comment the values part the sunburst is showed (without the values).

I am creating the sunburst figure with:

fig = px.sunburst(
    data,
    names='asset_and_liability',
    parents='parent',
    values='value',
)

The data is a dictionnary with 3 fields:

data = dict(
    asset_and_liability =[financial_status, "total_assets", "total_liabilities"]+ 
    ["total_current_assets"] + current_assets.keys().tolist() + ["total_non_current_assets"] 
    + non_current_assets.keys().tolist(),
    parent=["", financial_status, financial_status, "total_assets", *["total_current_assets"] 
            * len(current_assets), "total_assets", 
            *["total_non_current_assets"] * len(non_current_assets)],
    value = [ratio, total_assets, total_liabilities] + [sum(current_assets)]
    + current_assets.values.tolist() + [sum(non_current_assets)] + non_current_assets.values.tolist()

The values are:

>>> for var in data:
            for i in var.keys():
                 print(len(var[i]), var[i])
                 print("\n")

14 ['Conservatively financed', 'total_assets', 'total_liabilities', 'total_current_assets', 'cash', 'shortTermInvestments', 'netReceivables', 'inventory', 'otherCurrentAssets', 'total_non_current_assets', 'propertyPlantEquipment', 'goodWill', 'intangibleAssets', 'otherAssets']


14 ['', 'Conservatively financed', 'Conservatively financed', 'total_assets', 'total_current_assets', 'total_current_assets', 'total_current_assets', 'total_current_assets', 'total_current_assets', 'total_assets', 'total_non_current_assets', 'total_non_current_assets', 'total_non_current_assets', 'total_non_current_assets']


14 [3.7051177031436744, 275909000000, 74467000000, 152578000000, 18498000000, 101177000000,  27492000000, 999000000, 4412000000, 110253000000, 84587000000, 20624000000, 1979000000, 3063000000]

I tried with simpler, hard coded values:

    data = dict(
        asset_and_liability =[financial_status, "total_assets", "total_liabilities"]+ 
        ["total_current_assets"] + current_assets.keys().tolist() + ["total_non_current_assets"] 
        + non_current_assets.keys().tolist(),
        parent=["", financial_status, financial_status, "total_assets", *["total_current_assets"] 
                * len(current_assets), "total_assets", 
                *["total_non_current_assets"] * len(non_current_assets)],
        value = [0,1,2,3,4,5,6,7,8,9,10,11,12,13]
    ),
    fig = px.sunburst(
        data,
        names='asset_and_liability',
        parents='parent',
        values='value',
    )

But it remained the same, no graph when not comenting the value field.

Hi @MikeP I cannot reproduce the problem since you have undefined variables (ie the code is not standalone). Is there an error message in the web console (the javascript console of your browser) which could help us?

Hello @Emmanuelle, sure. My bad. Here is a standalone code:

    import plotly.express as px

    data = dict(
        asset_and_liability =["financial_status", "totalAssets", "totalLiab"],
        parent=["", "financial_status", "financial_status"],
        value = [3.7051177031436744,275909000000,74467000000]

    ),
    fig = px.sunburst(
        data,
        names='asset_and_liability',
        parents='parent',
        values='value',
    )

    return fig

And it still shows nothing.
I am running it through my jupyter notebook and there isnโ€™t any error.

ok, the problem is the comma , at the end of your definition of data, which makes data a tuple instead of a dict. If you remove the comma it works fine

import plotly.express as px

data = dict(
        asset_and_liability =["financial_status", "totalAssets", "totalLiab"],
        parent=["", "financial_status", "financial_status"],
        value = [3.7051177031436744,275909000000,74467000000]

    )
fig = px.sunburst(
        data,
        names='asset_and_liability',
        parents='parent',
        #values='value',
    )
fig.show()