✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

How to insert a sunburst in a dash app maintaing the color of it?

I created a sunburst figure with a color scale, but when inserting it into my app, it ignores the color code. How can I maintain the color??

mycode:

fig =go.Figure(go.Sunburst(
    ids = ids,
    labels= l ,
    parents= p ,
    values= v,
    branchvalues="total",
    marker=dict(
        colors=c,
        colorscale='rdylgn',),
    hovertemplate='<b>%{label} </b> <br> Total de questões: %{value}<br> Taxa de preenchimento: %{color:.0f} %',
    ))
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()

graph = dcc.Graph(figure = fig)

layout=[   
    graph
    ]
app.layout = html.Div(children = layout
)

app.run_server()

Hi @vialeca welcome to the forum! Humm, this should not happen. Could you please post here a standalone code reproducing the problem (you might have to use dummy data, or upload you data somewhere)? Thanks!

Just as a side note: you should not do fig.show in a Dash app, because the way the figure is shown is handled by dcc.Graph.

import dash
from dash.dependencies import Output, Input, State
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from selenium import webdriver
import threading
import DBAPI as DB
import dash_table
import pandas as pd
import pyodbc
import dash.dependencies
from datetime import datetime
import plotly.graph_objects as go

app = dash.Dash(__name__)
app.Title = 'Flemins'


global ids 
global l
global v
global p 
global c
labels = [\*]
parents=[\*]
values=[]
ids = []
colors = [\*]


cmd = "SELECT DISTINCT IdDoc FROM validacao"
DocsIds = crsr.execute(cmd).fetchall()

DocsNames = []
DocQuant = []


for IdDoc in DocsIds:
    Quem_no_doc = []
    IdDoc = IdDoc[0]
    cmd = "SELECT Nome FROM Documentos WHERE IdDoc = {}".format(IdDoc)
    Nome = crsr.execute(cmd).fetchone()[0]
    DocsNames.append(crsr.execute(cmd).fetchone()[0])

    cmd = "SELECT COUNT(Id) FROM validacao WHERE IdDoc = {} ".format(IdDoc)
    DocQuant.append(crsr.execute(cmd).fetchone()[0])
    cmd = "SELECT DISTINCT Quem FROM validacao WHERE IdDoc = {}".format(IdDoc)
    temp = [a[0] for a in crsr.execute(cmd).fetchall()]
    for a in temp:
        Quem_no_doc.append(a)
    feitadoc = 0
    Nfeitadoc = 0
    for Quem in Quem_no_doc:
        cmd = "SELECT COUNT(Validada) FROM validacao WHERE IdDoc = {} AND Quem = '{}' AND Validada = 'Sim'".format(IdDoc,Quem)
        feitas = crsr.execute(cmd).fetchone()[0]
        cmd = "SELECT COUNT(Validada) FROM validacao WHERE IdDoc = {} AND Quem = '{}' AND Validada = 'Não'".format(IdDoc,Quem)
        Nfeitas = crsr.execute(cmd).fetchone()[0]

#         if feitas != 0:
#             colors.appen(100)
#             labels.append('Validada')
#             ids.append(Quem + str(IdDoc)+'Validada')
#             values.append(feitas)
#         if Nfeitas != 0:
#             colors.append(0)
#             ids.append(Quem + str(IdDoc)+'Não Validada')
#             labels.append('Não Validada')
#             values.append(Nfeitas)
#         if feitas != 0:
#             parents.append(Quem+ str(IdDoc))
#         if Nfeitas != 0:
#             parents.append(Quem+ str(IdDoc))
        feitadoc += feitas
        Nfeitadoc = Nfeitas
        try:
            color = feitas/(Nfeitas+feitas)*100
        except:
            color = 100
        colors.append(color)
        labels.append(Quem)
        ids.append(Quem+ str(IdDoc))
        values.append(feitas + Nfeitas)
        parents.append(DocsNames[-1])

    try:
            color = feitadoc/(Nfeitadoc+feitadoc)*100
    except:
            color = 100
    colors.append(color)
    labels.append(DocsNames[-1])
    values.append(DocQuant[-1])
    parents.append('Documentos')
    ids.append(DocsNames[-1])

tot = 0
for i in DocQuant:
    tot += i

labels.append('Documentos')
values.append(tot)
parents.append('')
ids.append('Documentos')
colors.append('')    

labels.append('Documentos')
values.append(tot)
parents.append('')
ids.append('')
colors.append(100) 

labels.append('Documentos')
values.append(tot)
parents.append('')
ids.append('')
colors.append(100)  

labels.reverse()
values.reverse()
parents.reverse()
ids.reverse()
colors.reverse()


l = labels
v = values
p = parents
ids = ids
c = colors

fig  = go.Figure(go.Sunburst(
            ids = ids,
            labels= l ,
            parents= p ,
            values= v,
            #colors=c,
            branchvalues="total",
            marker=dict(
                colors=c,
                colorscale='rdylgn',
                showscale=True),
            hovertemplate='<b>%{label} </b> <br> Total de questões: %{value}<br> Taxa de preenchimento: %{color:.0f} %',
        maxdepth =3
            ))

graph = dcc.Graph(figure = fig,id='graph')

layout=[   
    graph
]


app.layout = html.Div(children = layout
)

app.run_server()


and my data is an access data base with the info.

I have no idea why, but it looks like it is ignoring the maker attribute

found a solution, just reinstalled the library and everything is fine now