Overview

In this article, we will learn how we can embed our Power BI report in HTML Page using JavaScript SDK. I have attached the code to this article. You can directly download the HTML file.

Before we start I prefer you to read my earlier articles:

Now, let’s get started!

Step 1

Copy the Azure App function URL.

Step 2

Create one HTML file and paste the following code snippet.
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  4. <meta name="viewport" content="width=device-width,initial-scale=1">
  5. <title>Power BI Embedded Demo</title>
  6. <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
  7. <script type="text/javascript" language="javascript" src="https://rawgit.com/Microsoft/PowerBI-JavaScript/master/dist/powerbi.min.js"></script> </script>
  8. </head>
  9. <body>
  10. <h1>Power BI Embedded Demo</h1>
  11. <div id="reportContainer" style="width: 80%; height: 800px;"></div>
  12. </body>
  13. <script>
  14. $(document).ready(function () {
  15. var getEmbedToken = "ADD Your Copied URL";
  16. $.ajax({
  17. url: getEmbedToken,
  18. jsonpCallback: 'callback',
  19. contentType: 'application/javascript',
  20. dataType: "jsonp",
  21. success: function (json) {
  22. var models = window['powerbi-client'].models;
  23. var embedConfiguration = {
  24. type: 'report',
  25. id: json.ReportId,
  26. embedUrl: json.EmbedUrl,
  27. tokenType: models.TokenType.Embed,
  28. accessToken: json.EmbedToken
  29. };
  30. var $reportContainer = $('#reportContainer');
  31. var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
  32. },
  33. error: function () {
  34. alert("Error");
  35. }
  36. });
  37. });
  38. </script>
  39. </html>
Step 3

Apply your Azure App function URL in the variable “getEmbedToken”.

Step 4

Run the code and check the result.

Conclusion

This is how we can embed our Power BI report in HTML Page. Hope you love this article! Stay connected with me.