Introduction
Both Python and Microsoft Power BI are two necessary tools that every Data Analyst/Business Intelligence Analyst use. What if we want to combine both of them in one project?
In this article we are going to see how we can simply embed a Power BI report within a Jupyter Notebook with the help of Python.
Install and Import libraries
Install
First of all, we need to install the IPython library :
pip install IPython (with pip)
conda install IPython (with Anaconda)
Import package IFrame
from IPython.display import IFrame
where IFrame (Inline Frame) is a component of IPython library which gives the ability to load an HTML element within a web page.
Load the report
In order to get the report, we will need to publish it via the Power BI Service and get the embedding link.
In order to do this:
- Open Power BI
- Select the report that you created and you want to embed into your Jupyter Notebook
- Press Publish from the Home tab and the Share section
- Sign In, if you haven’t done this from before
- Select your workspace
- Publish completed
Once the report is published, open Power BI Service (online) and once you open the report file, go to File -> Embed Report -> Website or Portal and then copy the code!
Once you successfully do the aforementioned, it’s time to write some Python code in our Jupyter Notebook.
Python Code
First, we have to create a variable named report that will hold the embedding link of our Power BI report:
report= IFrame(src=”https://app.powerbi.com/…..”, width = “2000”, height = “700”)
where in src you will put the embedding link, and on width, height parameters, you will pass the dimensions of your resulting embedded dashboard.
Finally, in order to display the report:
display(report)
Conclusion
Embedding a Power BI report in a Jupyter Notebook that uses Python code, is a combination that gives advantage to your notebook. Python, can really help with both the analysis of your data and the visualization, but the report will give a simpler, more organized way to present your insights.
So, next time you want to present your analysis, do not forget to combine Python and Power BI for a maximum result and an amazing presentation of your findings!