Hi everyone,
I have the following code that you can run on your own machine
import pandas as pd
import plotly.express as px
df = pd.read_csv(‘https://docs.google.com/spreadsheets/d/e/2PACX-’
‘1vTPpPotcptmOX2CBhvzWUbRJNCXFqkUIicECxWRKg1uszebqlPsGZHVv4EBDOEkN1J5dzr3_K1MW1qS/pub?gid=0&single=true&output=csv’)
df_totals = df.groupby([“country”, “region”]).volunteers.sum().reset_index()
fig_pie = px.pie(df_totals, names='region', values='volunteers', hole=0.5, color='region',custom_data=['region','volunteers'])
print(df_totals.info())
# Donut Chart Styling
fig_pie.update_traces(textposition='inside')
fig_pie.update_layout(uniformtext_minsize=12, uniformtext_mode='hide')
fig_pie.update_traces(hovertemplate="<b>Okres:</b> %{customdata[0]}<br><b>Celkom:</b> %{customdata[1]}")
fig_pie.update_layout(
hoverlabel=dict(
bgcolor="#273B80",
font_size=16,
font_family="sans-serif"
)
)
fig_pie.show()
After trying using names
and values
for my hovertemplate, without it fetching the values I have assigned both columns to custom_data
Here is a sample of the results:
Showing a number in customdata[0] (that should only have the region name) and not rendering customdata[1]
Rendering customdata[1] but showing a different number from the one that appears, out of nowhere, on customdata[0]
Am I doing something wrong, or is this a bug?
Thank you in advance for your help!
Disclaimer: The solutions presented will be used in non-profit NGO project. No commercial use of the solution will be made.