I wrote a function to return plotly fig on Streamlit and display it using st.plotly_chart but I am unable to change the color of labels in the Sankey chart. Same function works without any issues if I run it locally outside of Streamlit environment. This is specific to font color, I am able to change other attributes.
def make_sankey_chart(df, name):
nodes =
for i in df.columns[:-1].to_list():
nodes.extend(set(df[i]))
nodes_dict = {value: index for index, value in enumerate(nodes)}
node_labels = list(nodes_dict.keys())
n = len(df.columns) - 1
i = 0
source, target, value = [], [], []
while i < n-1:
group_df = df.groupby(df.columns[i:i+2].to_list())[df.columns[-1]].sum().reset_index()
source.extend(group_df.iloc[:,0].map(nodes_dict).to_list())
target.extend(group_df.iloc[:,1].map(nodes_dict).to_list())
value.extend(group_df.iloc[:,-1].to_list())
i += 1
fig = go.Figure(data=[go.Sankey(
node=dict(
pad=15,
thickness=20,
line=dict(color="black", width=0.5),
label=node_labels
),
link=dict(
source=source,
target=target,
value=value
)
)])
# Update layout
fig.update_layout(
title=name,
font=dict(color='blue', size=15)
)
return fig
Mandatory questions:
-
Are you running your app locally or is it deployed?
Local -
If your app is deployed:
a. Is it deployed on Community Cloud or another hosting platform?
b. Share the link to the public deployed app.
NA -
Share the link to your app’s public GitHub repository (including a requirements file).
NA -
Share the full text of the error message (not a screenshot).
NA -
Share the Streamlit and Python versions.
Streamlit version 1.31.0 and Python 3.9