How to display only part of a variable in hovertemplate / texttemplate text?

I figured out a solution on my own.

In my question’s example above, if I replace location_text with a list of lists of strings (instead of just a list of strings with _ separators) then I can just call the desired string directly by its index. Example:

location_text = [
    ["Topeka", "Kansas", "USA", "Earth", "MilkyWay"],
    ["Montreal", "Quebec", "Canada", "Earth", "MilkyWay"]
]

go.Figure(
    go.Sunburst(
        text = location_text,
        hovertemplate= f"City: {text[0]} Country: {text[2]}"
    )
)
2 Likes