✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Sankey Diagram fig.show() won't load in chrome

The graphs in this tutorial load fine https://plotly.com/python/sankey-diagram/

For example, I have no problem loading this in under a second

import plotly.graph_objects as go
import urllib, json

url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json'
response = urllib.request.urlopen(url)
data = json.loads(response.read())

# override gray link colors with 'source' colors
opacity = 0.4
# change 'magenta' to its 'rgba' value to add opacity
data['data'][0]['node']['color'] = ['rgba(255,0,255, 0.8)' if color == "magenta" else color for color in data['data'][0]['node']['color']]
data['data'][0]['link']['color'] = [data['data'][0]['node']['color'][src].replace("0.8", str(opacity))
                                    for src in data['data'][0]['link']['source']]

fig = go.Figure(data=[go.Sankey(
    valueformat = ".0f",
    valuesuffix = "TWh",
    # Define nodes
    node = dict(
      pad = 15,
      thickness = 15,
      line = dict(color = "black", width = 0.5),
      label =  data['data'][0]['node']['label'],
      color =  data['data'][0]['node']['color']
    ),
    # Add links
    link = dict(
      source =  data['data'][0]['link']['source'],
      target =  data['data'][0]['link']['target'],
      value =  data['data'][0]['link']['value'],
      label =  data['data'][0]['link']['label'],
      color =  data['data'][0]['link']['color']
))])

fig.update_layout(title_text="Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
                  font_size=10)
fig.show()

But when I try it with my own data,

{'label': ['Onboarding',
           'TAM Queue',
           'Enterprise Level 1',
           'CSM',
           'Unassigned',
           'Technical Account Managers',
           'CL Phones Testing',
           'Enterprise Level 2',
           'TAM Queue',
           'Enterprise Level 1',
           'CSM',
           'Support Level 1',
           'MSP Level 1',
           'Enterprise Level 1',
           'Support Level 1',
           'MSP Level 1',
           'Enterprise Level 2',
           'Enterprise Level 2',
           'TSE-Handover',
           'MSP Level 2',
           'Enterprise Level 1',
           'Support Level 1',
           'Enterprise Level 1',
           'TSE-Handover'],
 'source': [4,
            4,
            4,
            4,
            6,
            4,
            4,
            2,
            4,
            5,
            4,
            5,
            2,
            1,
            1,
            2,
            0,
            3,
            2,
            2,
            11,
            2,
            2,
            2,
            2,
            2,
            11,
            11,
            1,
            1,
            2,
            2,
            7,
            11,
            12,
            11,
            11,
            2,
            3,
            2,
            11,
            11,
            2,
            2,
            12,
            7,
            12,
            12,
            7,
            7,
            2,
            2,
            2,
            2,
            7,
            19,
            18,
            7,
            7,
            2,
            11,
            2,
            18],
 'target': ['20481586',
            '20475577',
            '21736484',
            '27601137',
            '33649147',
            '20478276',
            '33649147',
            '20464382',
            '28086067',
            '27601137',
            '32616907',
            '20475577',
            '20478276',
            '20478276',
            '20475577',
            '20481586',
            '20475577',
            '35878328',
            '27601137',
            '33649147',
            '20475577',
            '35878328',
            '360005866952',
            '360005883591',
            '20463183',
            '21873400',
            '20464382',
            '20481586',
            '360005867112',
            '20478276',
            '20475577',
            '20475577',
            '27601137',
            '27601137',
            '20464382',
            '20481586',
            '21873400',
            '20475577',
            '27966326',
            '27601137',
            '20478276',
            '20475577',
            '360006682891'],
 'value': [7038,
           16812,
           59,
           1976,
           19,
           21,
           414,
           130,
           40,
           125,
           41,
           21,
           47,
           4,
           28,
           2,
           15,
           25,
           13,
           1,
           3,
           2,
           2,
           3,
           1,
           2,
           13,
           2,
           1,
           4,
           5,
           6,
           1,
           1,
           651,
           297,
           155,
           19,
           9,
           7,
           1835,
           4384,
           28]}

It gets stuck loading forever.

Here is my code:

import plotly.graph_objects as go
from pathlib import Path
import json
from pprint import pprint

link = json.load(open(str(Path.home()) + '/sankey_transform_3.txt', 'r'))

pprint(link)

fig = go.Figure(data=[go.Sankey(
    node=dict(
      pad=15,
      thickness=15,
      line=dict(color='black', width=0.5),
      label=link['label'],
      color='blue'
    ),
    link=dict(
        source=link['source'],
        target=link['target'],
        value=link['value']
    )
)])

fig.update_layout(title_text='Flows between Queues', font_size=10)
fig.show()

Solved it. Posting the data here helped me realize that my Target list was not mapped to Source Indexes properly.