Black Lives Matter. Please consider donating to Black Girls Code today.

Blank output with go.Sunburst

Hi, all, I have a simple structured dataset, just like:

order_list	      date	    QTY	 GPM   	city	      state	    stores
SMDBJO18924721	2019/1/1	153	0.0624	Torrance	California	Torrance_store_1
SMDBJO18676825	2019/1/1	7	0.2938	Aurora	Colorado	Aurora_store_3
SMDBJO18302956	2019/1/1	255	0.7366	Pembroke Pines	Florida	Pembroke Pines_store_4
SMDBJO18467792	2019/1/1	59	0.1677	Lakewood	Colorado	Lakewood_store_4
SMDBJO18985989	2019/1/1	324	0.248	Louisville	Kentucky	Louisville_store_1
SMDBJO18229068	2019/1/1	214	0.584	Cedar Rapids	Iowa	Cedar Rapids_store_1
SMDBJO18973145	2019/1/1	322	0.9469	Lubbock	Texas	Lubbock_store_1
SMDBJO18946982	2019/1/1	189	0.4763	Sioux Falls	South Dakota	Sioux Falls_store_4
SMDBJO18836305	2019/1/1	75	0.2101	Costa Mesa	California	Costa Mesa_store_1
SMDBJO18333923	2019/1/1	226	0.5179	Lafayette	Louisiana	Lafayette_store_4
SMDBJO18644837	2019/1/1	186	0.5382	Carrollton	Texas	Carrollton_store_4
...(43791 rows)

I can get correct output by using plotly.Express in Dash:

def sunburst_trace():
    data_pivot_select = pd.pivot_table(df_all.set_index('date')[timeCondition], index=['state','city','stores'],values=['GPM'],aggfunc=[sum]).reset_index()
    fig = px.sunburst(data_pivot_select,path=['state','city','stores'], values=['GMP'])
    return fig

but when I using plotly.graph_objs in Dash as below, I got Blank Output:

def sunburst_trace():
    data_pivot_select = pd.pivot_table(df_all.set_index('date')[timeCondition], index=['state','city','stores'],values=['GPM'],aggfunc=[sum]).reset_index()
    trace=[go.Sunburst(
                  ids=data_pivot_select.stores,
                  labels=data_pivot_select.city,
                  parents=data_pivot_select.state,
                  values=data_pivot_select.GPM,
                  maxdepth=3,
                  )]
    return dict(data=trace, layout=layout)

Thanks for the help, anything that can guide me in the right direction would be much appreciated.

Hi @SandK! The path attribute syntax with px.sunburst has no equivalent with go.Sunburst. With go.Sunburst every parent must be defined and here the values of the state column do not have a parent defined, hence the error. Here you need to use px.sunburst, or you need to build the list of parents and ids so that all sectors have an id and a parent, as in the examples of https://plot.ly/python/sunburst-charts/

Thank you @Emmanuelle for your replying! I thought it’s the same as pandas.Pivot_table. :sweat_smile: