Forum Discussion

vishnumohanout's avatar
vishnumohanout
Frequent Visitor
4 years ago

Python visualizations that work in Power BI desktop, but fails when published.

I have been trying to build out a Python visualization within a Power BI report.  Many of the interesting Python libraries are not supported here. Finally, managed to get it to work with Seaborn (Python library). Works perfectly well in the desktop edition, but when I published the report, it throws all sorts of bogus errors (example provided).


Example:

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset = pandas.DataFrame(Duration (d), Type, Cumulative Days, Phase Sequence, Sequence Phase)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import seaborn as sns
import matplotlib.pyplot as plt

df_refined = dataset[['Type', 'Phase Sequence', 'Sequence Phase', 'Cumulative Days', 'Duration (d)']]
df_refined = df_refined.groupby(['Type', 'Phase Sequence', 'Sequence Phase']).sum().reset_index()

df_cumulative = df_refined[['Type', 'Phase Sequence', 'Sequence Phase', 'Duration (d)']]
df_planned = df_cumulative[df_cumulative['Type']=="Planned"].groupby(['Type', 'Phase Sequence', 'Sequence Phase']).sum().reset_index()
df_actual = df_cumulative[df_cumulative['Type']=="Actual"].groupby(['Type', 'Phase Sequence', 'Sequence Phase']).sum().reset_index()
df_actual['Cumlative Duration'] = df_actual['Duration (d)'].cumsum()
df_planned['Cumlative Duration'] = df_planned['Duration (d)'].cumsum()
df_union = pandas.concat([df_planned, df_actual]).reset_index()
df_union.drop(columns="index", inplace=True)

sns.set_theme(style="whitegrid")

# Initialize the matplotlib figure
f, ax1 = plt.subplots(figsize=(24, 10))

# Sort values 
#temp = df_modified1.sort_values("Phase Sequence")
temp = df_union

# Plot the horizontal bar graph
sns.set_color_codes("pastel")
sns.barplot(y="Sequence Phase", x="Duration (d)", orient="h", ci=None, hue="Type", data=temp, ax=ax1)

ax2 = ax1.twiny()
ax2.set_xlim(0,75)
#ax1.grid(False)
ax2.grid(False)

#ax = sns.ecdfplot(data=df_union, x="Cumlative Duration", hue="Type", complementary=False)
sns.lineplot(x="Cumlative Duration", y="Sequence Phase", hue="Type", palette=['blue', 'orange'], linewidth=3, data=df_union, ax=ax2)

# Add a legend and informative axis label
ax2.legend(ncol=2, loc="lower right", frameon=True)
ax2.set( ylabel="Duration (in days)", xlabel="Actual vs Planned Activities")
sns.despine(left=True, bottom=True)
plt.show()
Script Runtime Error

[S-fb1031da-4b56-4b45-903b-2a0d189b6ad3][S-fb1031da-4b56-4b45-903b-2a0d189b6ad3]AttributeError: module 'seaborn' has no attribute 'set_theme'
Please try again later or contact support. If you contact support, please provide these details.

Activity ID: a55531d4-6d27-4b09-b322-7782cb9a996d
Request ID: 78524267-c082-57db-799b-3a7c06f694bb
Correlation ID: fdae727e-c54c-bd3b-23cd-096209bf4822
Time: Mon Jun 13 2022 12:12:29 GMT+0400 (Gulf Standard Time)
Service version: 13.0.18442.44
Client version: 2206.1.11664-train
Cluster URI: https://wabi-north-europe-j-primary-redirect.analysis.windows.net/

 

Funny thing is, Seaborn has a "set_theme" module and yet it gives you an error claiming the opposite. This is one of many such errors that the published version of the report will show. 

 

Would love to find out any fixes for this issue? Am I missing something, here?

 

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi vishnumohanout 

     

    Have you installed the personal gateway that is required in such a scenario?

    For reference:

    Python visualizations in Power BI Service

    Here is a solved post with similar problem like yours. I hope it could help you solve your problem.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.