Install-Package Microsoft.PowerBI.JavaScript -Pre
npm install powerbi-client
bower install powerbi-client
Add the Power BI script include before your apps closing </body>
tag
<script src="/bower_components/powerbi-client/dist/powerbi.js"></script>
Add your access token to your app so it can be accessed.
This can be set statically or dynamically via JavaScript.
<script>
window.powerbi = window.powerbi || {};
window.powerbi.accessToken = '{{AccessToken}}';
</script>
Power BI will automatically search your apps DOM for Power BI embed components on page load.
If your app is dyanamically adding new embed components after page load you will need to manually initialize them via JavaScript.
The report will automatically be embedded based on the size of it's container.
To override the default size of the embeds simply add a CSS class attribute or inline styles for width & height.
Add the following markup to embed a Power BI Report
Embed via full qualified Report EmbedUrl
.
<div powerbi-embed="{{EmbedUrl}}" powerbi-report></div>
Or, embed with your ReportId
<div powerbi-embed powerbi-report="{{ReportId}}"></div>
<script>
var elem = document.getElementById('#myReport');
var report = window.powerbi.get(elem);
report.fullscreen();
</script>
You can optional pass a DOM element to scope the intialization
window.powerbi.init();
Setup the a new DOM element with the same structure as above.
Call the embed
function passing in the single element.
window.powerbi.embed(element);
Returns an instance of the Power BI component associated with an element
var myPowerBIComponent = window.powerbi.get(element);