plotly / plotly/plotly.py

Sankey is not updated on callback

Ouverte
#3,059 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug P3
Langage dominant
Python
Étoiles
18.8k
Forks
2.8k
Merge moyen
16 h 26 min
PR mergées (30 j)
21

Description

Python 3.8.5; Plotly 4.14.1; Dash 1.19.0

Plotly’s Sankey is not updated with new data on callbacks. A Sunburst plot based on the same data works correctly, as you can see in this example.

value data are changed and passed to JS correctly:

import plotly.graph_objs as go

import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Output, Input
import random

app = dash.Dash(__name__)
app.layout = html.Div(
    [
        html.Button('Change values',
                    id='btn_change',
                    n_clicks=0),
        
        dcc.Graph(
            id="fig_sunburst",
            figure=go.Figure(),
            animate=True,
        ),
        dcc.Graph(
            id="fig_sankey",
            figure=go.Figure(),
            animate=True,
        ),

        dcc.Interval(
            id=f"update",
            interval=2000,
            n_intervals=0
        ),
    ],
)

@app.callback(
    Output('fig_sunburst', 'figure'),
    Output('fig_sankey', 'figure'),
    Input('btn_change', 'n_clicks')
)
def traces_update(n_clicks):
    print(f"update {n_clicks}")
    
    # random data
    a1 = random.randint(10, 100)
    a2 = random.randint(10, 100)
    a3 = random.randint(10 ,100)
    a0 = a1+a2+a3
    
    b1 = random.randint(10, 100)
    b2 = random.randint(10, 100)
    b0 = b1+b2
    
    tot = a0+b0
    
    fig_sunburst = go.Figure(
        go.Sunburst(
            ids=['tot', 'a0', 'a1', 'a2', 'a3', 'b0', 'b1', 'b2'],
            labels=['tot', 'a0', 'a1', 'a2', 'a3', 'b0', 'b1', 'b2'],
            parents=['', 'tot', 'a0', 'a0', 'a0', 'tot', 'b0', 'b0'],
            values=[tot, a0, a1, a2, a3, b0, b1, b2],
            branchvalues="total",
            insidetextorientation='horizontal',
        )
    )
    fig_sunburst.update_layout(go.Layout(width=400, height=400,
                                 margin=dict(t=20, l=20, r=20, b=20),))
        
    fig_sankey = go.Figure(
        go.Sankey(
            node=dict(
                label=['tot', 'a0', 'a1', 'a2', 'a3', 'b0', 'b1', 'b2'],
            ),
            link=dict(
                source=[0, 0, 1, 1, 1, 5, 5],
                target=[1, 5, 2, 3, 4, 6, 7],
                value=[a0, b0, a1, a2, a3, b1, b2],
            ),
        )
    )

    fig_sankey.update_layout(go.Layout(width=400, height=400,
                                 margin=dict(t=20, l=20, r=20, b=20),))
    
    print(fig_sankey["data"][0]["link"]["value"])
    
    return fig_sunburst, fig_sankey

app.run_server()

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter l’exemple fourni de callback Python Dash avec les versions indiquées de Python, Plotly et Dash, puis comparez les mises à jour de Sankey et Sunburst après avoir cliqué sur « Change values. » Suivez le callback-to-graph update path pour les données Sankey ; c’est terminé lorsque les valeurs des liens Sankey s’actualisent visiblement lors des callbacks, comme celles de Sunburst.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
data-visualization
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
42/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.