Learn how to seamlessly integrate Lovable with Microsoft Power BI with our step-by-step guide, making data connection, visualization, and analytics a breeze.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
In your Lovable project, locate the main HTML file (for example, index.html). Add a script tag to load the Power BI JavaScript client library. Since Lovable doesn't support a terminal, you need to include this script tag directly in your HTML file. Insert the following snippet within the <head> or at the end of the <body> section:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/powerbi-client.min.js"></script>
This script tag loads the Power BI client so that you can use its methods from your TypeScript code.
Create a new file called powerbiIntegration.ts in your project's source directory. This file will contain a class to handle embedding a Power BI report.
// powerbiIntegration.ts
// Define a class to handle Power BI operations
export class PowerBIHandler {
private powerbi: any;
constructor() {
// Ensure the Power BI client library is available as a global object
this.powerbi = window['powerbi'];
}
// Method to embed a Power BI report into a container in the DOM
embedReport(containerId: string, embedConfig: any): void {
const reportContainer = document.getElementById(containerId);
if (!reportContainer) {
console.error("Container element not found: " + containerId);
return;
}
this.powerbi.embed(reportContainer, embedConfig);
}
}
This TypeScript code creates a class named PowerBIHandler with a method embedReport that takes a container ID (where the report will be rendered) and an embed configuration object.
In the HTML file where you want the Power BI report displayed (for instance, in index.html), add a div element that will serve as the container. Insert it where you want the report to appear:
<div id="reportContainer" style="height:600px; width:800px;"></div>
This container will be used by the embedReport method to render the Power BI report.
Within your main TypeScript file (or any file from which you want to trigger the embedding of the report), import the PowerBIHandler class. Then, create an instance of it, build your embed configuration, and call the embedReport method.
Add the following code snippet in the appropriate project file (for example, in main.ts):
import { PowerBIHandler } from './powerbiIntegration';
// Define the embed configuration object for the report
const embedConfig = {
type: 'report',
tokenType: powerbi-client.models.TokenType.Embed, // Use the TokenType provided by the Power BI client
accessToken: 'YOUREMBEDTOKEN', // Replace with your actual embed token
embedUrl: 'YOUREMBEDURL', // Replace with your report's embed URL
id: 'YOURREPORTID', // Replace with your report ID
permissions: powerbi-client.models.Permissions.All,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: false
}
};
// Create an instance of the PowerBIHandler and embed the report into the container with the ID 'reportContainer'
const powerbiHandler = new PowerBIHandler();
powerbiHandler.embedReport('reportContainer', embedConfig);
Make sure to replace YOUREMBEDTOKEN, YOUREMBEDURL, and YOURREPORTID with the appropriate values obtained from your Power BI setup.
Since Lovable does not have a terminal for dependency installation, ensure that:
powerbiIntegration.ts and your main code file with the embed logic are referenced in your project so that they are included in the final build.Once everything is saved and compiled (or the browser refreshes the changes), the Power BI report should embed into the <div id="reportContainer"> element on your page.
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.