Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Use Plotly with Python Script in Power BI

Hello,

 

I'm a deep python user so would like to use it in Power BI. I have tried matplotlib and seaborn library - there are no error to use them as long as I put "plt.show()" in the scripts. However, these are all static charts and I would like to use some interactive features using Plotly Module. When I use plotly, there always shows an error of "no image created".

 

I know there is solutions in R to use Plotly but is there a solution to use Plotly with Python in Power BI?

 

Thank you.

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

I'm afraid that Plotly is not supported in Power BI currenly.

Based on the blog, only the following Python packages (non-Intel MKL) are currently supported for use in your Power BI reports.

  • matplotlib
  • numpy
  • pandas
  • scikit-learn
  • scipy
  • seaborn
  • statsmodels

In addition, you could refer to this similar thread which should make sense.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

17 REPLIES 17
vishnuvvardhan
Regular Visitor

Hi  there!

 

I recently tried to create a gauge chart with dial in Power BI using python script. There are 2 variants which I attempted:

1. Using Matplotlib pyplot

2. Using plotly

 

The one using Matplotlib is actually a polar chart with it's bottom half invisible. To develop a gauge chart is more of a workaround but it's implementation in Power BI though is pretty straightforward and more compatible in terms of display. No workarounds needed! Simply create the custom visual you need and show it in the BI report.

 

On the other hand, the variant using Plotly has better & clear features as there is a builtin functionality meant for Gauge charts. While it's super simple to create the kind of gauge chart you need, displaying it inside the python visual in PBI is a hassle! You are constantly bombarded with the following error:Screenshot 2024-07-17 005632.png

 

To solve this, I had to convert the plot to an image using kaleido.

fig.write_image('gauge_chart.png', engine='kaleido')

 

Then I loaded the image into Matplotlib with this:

# Read the saved image and display it using matplotlib
img = Image.open('gauge_chart.png')
plt.imshow(img)
plt.axis('off')  # Hide the axes
plt.show()

 

And voila! The plot will now appear in the python visual.

 

Though the flexibility to develop better gauge charts is present in Plotly, it's implementation is quite a puzzle! And this needs more dependencies unlike the Matplotlib version!

Had to use all of these:

import plotly.graph_objects as go
import pandas as pd
import plotly.io as pio
from PIL import Image
import matplotlib.pyplot as plt

 

 

Hope this helps someone!

 

Thanks!

_robind
New Member

Hi @v-piga-msft, although not ideal, a static plotly image would be ok for now, but this requires fig.write_image('test.png') which requires kaleido.  What are the chances of having kaleido added to the list of approved libraries, so that users can at least view advanced plotly graphs that are not available in matplotlib or seaborn, like their go sankey plot...?

stevedep
Memorable Member
Memorable Member

Hi,

 

You could take a look at this blog post. It describes how to add an interactive Plotly Chart in Power BI. Its quite easy when you follow these steps. 

 

Kind regards, 

 

Steve. 

Anonymous
Not applicable

@Steve, the link can be opened, can you please check if the link is still valid?

Thanks,

Cherie

Hi,

The link is working for me, but I also added it on the blog over here.

Kind regards, Steve

Anonymous
Not applicable

Hi @stevedep ,

 

Thanks a lot. the artical does help, and i am following.

 

Regards,

Cherie

guilhermesilva
Regular Visitor

I am able now to make a plotly graph inside Power BI using python.
However, Power BI shows my graph in a new window of my browser (instead of showing into the Power BI framework).

The last line of my code is

fig.show()

How could I print it into the Power BI framework? 

Anonymous
Not applicable

use fig.write_image('test.png'). but it's a static image, can't be interactive.

HamidBee
Impactful Individual
Impactful Individual

I am using this example sample code:

 

import plotly.express as px
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
fig.write_image('test.png')
 
however it doesn't seem to work. When I use fig.show() it will show the chart but in a web browser.

I believe that this was always the case and that Plotly is still not integrated in Power BI via Python. Meaning, it still won't show graphs in Power BI. I still can't understand why Plotly works with R and not Python. To the Power BI team at Microsoft, please fix this.

ramzibenamara
New Member

Hi any updates on how to use plotly with Python script in Power BI, I can use it but the visualization come into a browser not into the power bi dashboard.

Any luck on plotly and Power BI?

Nop the only way is to do it In R not in python 

Just so that I understand correctly. Plotly in Python only works with R?

plotly in Power BI only works with R

That is really dissapointing news.

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

I'm afraid that Plotly is not supported in Power BI currenly.

Based on the blog, only the following Python packages (non-Intel MKL) are currently supported for use in your Power BI reports.

  • matplotlib
  • numpy
  • pandas
  • scikit-learn
  • scipy
  • seaborn
  • statsmodels

In addition, you could refer to this similar thread which should make sense.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.