How to get an extra value on the labels for a Pie Chart

I’ve been butting heads with 2 particular issues.

The first one’s rather easy. When I execute my script, 4 tabs open in my browser (usually, about 20% of the time, the tabs open and terminal stops; I have to Ctrl+C and restart it). If successful, the first one is the graph and the other 3 are just spinning, never loading anything. I’m kicking off the script from VS Code, could that be it?

The second one is a little more complicated. So my pie chart is the distribution of my cryptocurrency assets. For each piece of the pie, I would like:

  1. The token name (i.e. ETH)
  2. The amount of tokens held (i.e. 4.38573927592) which I’d round to make look pretty
  3. The USD value of said tokens (i.e. $5,305.35)
  4. The percentage of my portfolio that is that particular token

I can get 1, 3, and 4, but 2 won’t work. I’ve tried going through Plotly docs and Google but not finding anything that results in the desired outcome.

Prior to this code is just a GET request to an API that returns the data:

output = json.dumps(json.loads(res.content), indent=4)

data = json.loads(output)

log = []

total_usd = 0

for token in data:
    if token['amount'] * token['price'] > 0.01 and not token['symbol'].lower() in blacklist:
        temp = {}

        temp["name"] = token['name']
        temp["symbol"] = token['symbol']
        temp["token_price"] = token['price']
        temp["amount"] = token['amount']
        temp["usd_value"] = token['amount'] * token['price']


labels = []
values = []
amounts = []

usd_val = 0

for t in log:

    usd_val += t['usd_value']


fig = go.Figure(data = [go.Pie(labels = labels, values = values, texttemplate="%{label} / %{amount:.2f} / $%{value:,.2f} / %{percent}", insidetextorientation = 'radial', rotation = 310)])

And when I execute this, the %{amount:.2f} is printed instead of the desired associated value.

I tacked in that print(amounts) so the console kicks back a list like so:

[4.9136854038244415, 0.23616897657059374, 2.933094278959343, 0.02796276, 2.81341616, 0.015665620499478162, 19.46981420335119]

So the data is valid, is it a key thing? I figured variables are variables so I’d be able to use it.

Any pointers would be appreciated. TIA!