Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@nibo-ai/ngx-powerbi
Advanced tools
TypeScript library for embedding Power BI assets (reports/dashboards/tiles) in your application. This TypeScript library is built on top of the official powerbi-client library provided by Microsoft.
TypeScript library for embedding Power BI assets (reports/dashboards/tiles) in your application. This TypeScript library is built on top of the official powerbi-client library provided by Microsoft.
* Please mind that this README is a work in progress, i will try to create a sample application that utilizes this library and update this README accordingly.
This library has a peer dependency on the official Microsoft powerbi-client library so install that first: NPM:
npm install powerbi-client
Install the ngx-powerbi library:
npm install ngx-powerbi
There are multiple ways to embed the Power BI assets in your application. The Power BI library needs an access token with required privileges for accessing the Power BI assets. You must have a Power BI Pro license or a trial account to access the Power BI embedded functionality. For details about Power BI account requirements and embedding, refer my Power BI Overview and Angular Embedding How-to article.
Here are some of the sample ways of embedding a Power BI report in your application:
Method 1
Pick up and play: Use the included Power BI component directly in your component HTML file.
import { NgxPowerBiModule } from 'ngx-powerbi';
@NgModule({
imports: [
...
...
NgxPowerBiModule
],
exports: ...,
declarations: ...
})
Use the provided component attribute to embed a Power BI asset:
<ngx-powerbi-component type="report"
id="[put-report-id-here]"
embedUrl="https://app.powerbi.com/reportEmbed?reportId=[put-report-id-here]&groupId=[put-group-id-here]"
tokenType="Aad"
accessToken="[put-access-token-here]"
on-embedded="onEmbedded($event)">
</ngx-powerbi-component>
Optional: Implement the onEmbedded(report: pbi.Report)
in your component class if you want to capture Power BI embedded component events.
Method 2
Use the Power BI configuration HTML attributes in a div + Power BI embedded service. The component.html should look like this:
<div id="dashboard-container"
powerbi-dashboard-id="[put-dashboard-id-here]"
powerbi-access-token="[put-access-token-here]"
powerbi-embed-url="https://app.powerbi.com/dashboardEmbed?dashboardId=[put-dashboard-id-here]&groupId=[put-group-id-here]"
powerbi-type="dashboard"
powerbi-settings-filter-pane-enabled="false"
powerbi-settings-nav-content-pane-enabled="true">
</div>
In the component.ts file, use the provided embed API to embed the Power BI asset in this div component. Refer 'Method 3' for details about the usage of Power BI service and embed API. Since, we are specifying the configuration through HTML attributes here, the config object required by the embed API in the TypeScript code can be empty.
Method 3
If you want more fine-grain control of the embedding functionality, use the provided Power BI embedded service as per the instructions below:
<div id="pbi-container"></div>
import { NgxPowerBiService } from 'ngx-powerbi';
export class ReportsContainer implements OnInit {
private powerBiService: NgxPowerBiService;
private pbiContainerElement: HTMLElement;
constructor() {
this.powerBiService = new NgxPowerBiService();
...
}
ngOnInit() {
this.pbiContainerElement = <HTMLElement>(document.getElementById('pbi-container'));
...
...
}
Also, import any Power BI components that you need in your component.ts file:
import { Page } from 'page';
import { Report } from 'report';
import { Dashboard } from 'dashboard';
For example, if you want to embed a report, import the Report component and so on.
this.powerBiService.embed(this.pbiContainerElement, config);
This API call will embed the Power BI component in the div element we created earlier. Notice the 'config' object we have provided as a 2nd argument in the embed() API call above. Refer the 'Embed Configuration' section for details about this.
report.on('loaded', function(event) {
report.getPages().then(function(pages) {
console.log('report loaded, number of pages: ', pages.length);
// We only want to handle the 'loaded' event once
report.off('loaded');
});
});
report.off('pageChanged');
report.on<{ newPage: Page }>('pageChanged', event => {
console.log('Page changed:', event.detail.newPage.displayName);
});
For more details about event handling, refer the Microsoft wiki page: https://github.com/Microsoft/PowerBI-JavaScript/wiki/Handling-Events
The Power BI library provides a default embed configuration but you can define your own configuration too. For Method 2 above, the embed configuration has been provided through the HTML attributes itself, so the config object in our TypeScript code can be empty. For Method 3, we need to specify the embed configuration in the component.ts TypeScript code.
Sample configuration for dashboard:
const config = {
type: 'dashboard',
dashboardId: '[put-dashboard-id-here]',
embedUrl:
'https://app.powerbi.com/dashboardEmbed?' +
'dashboardId=[put-dashboard-id-here]' +
'&groupId=[put-group-id-here]',
accessToken: [put-access-token-here]
};
Sample configuration for report:
const config = {
type: 'report',
id: '[put-report-id-here]',
embedUrl:
'https://app.powerbi.com/reportEmbed?' +
'reportId=[put-report-id-here]' +
'&groupId=[put-group-id-here]',
accessToken: [put-access-token-here],
settings: {
filterPaneEnabled: this.filterPaneEnabled,
navContentPaneEnabled: this.navContentPaneEnabled
}
};
This config object can then be passed to this.powerBiService.embed(this.pbiContainerElement, config)
.
For more details about embed configuration, refer the Microsoft wiki page: https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details
The Power BI embedding functionality requires an access token to the Power BI Pro account. Retrieving the access token is not part of the web client functionality or this library, it should ideally be fetched by the server and served to the web client using a REST call or similar mechanism.
This TypeScript library is built on top of the official powerbi-client library provided by Microsoft and references some code from PowerBI-Angular2 library.
FAQs
TypeScript library for embedding Power BI assets (reports/dashboards/tiles) in your application. This TypeScript library is built on top of the official powerbi-client library provided by Microsoft.
The npm package @nibo-ai/ngx-powerbi receives a total of 7 weekly downloads. As such, @nibo-ai/ngx-powerbi popularity was classified as not popular.
We found that @nibo-ai/ngx-powerbi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.