Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Last active October 5, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnaanaril/211f5b390a5e7e038b7a67dfe387fb29 to your computer and use it in GitHub Desktop.
Save krishnaanaril/211f5b390a5e7e038b7a67dfe387fb29 to your computer and use it in GitHub Desktop.
Embed Power BI tile for organization
getToken() {
this.adalSrv.context.acquireToken(environment.powerBIEndpoint, (error, token) => {
if (error || !token) {
// TODO: Handle error obtaining access token
console.error('ERROR:\n\n' + error);
return;
}
// Get available dashboards
this.adalSrv.getDashboardsInGroup(environment.groupId).pipe(mergeMap((res, ind) => {
// select the first among the available dashboards
this.dashboardId = res["value"][0]["id"];
// Get available tiles in the selected dashboard
return this.adalSrv.getTilesInGroup(environment.groupId, this.dashboardId);
})).subscribe((res) => {
// select the first tile to embed
this.getTile(res["value"][0]["id"], res["value"][0]["embedUrl"]);
});
});
}
getTile(id: string, embedUrl: string) {
console.log(id + " : " + embedUrl);
var embedConfiguration = {
type: 'tile',
id: id,
embedUrl: embedUrl,
tokenType: pbi.models.TokenType.Aad,
accessToken: this.adalSrv.context.getCachedToken(environment.powerBIEndpoint),
dashboardId: this.dashboardId
};
// Grab the reference to the div HTML element that will host the report.
const tileContainer = <HTMLElement>document.getElementById(
'embedTile'
);
const report = this.powerbi.embed(
tileContainer,
embedConfiguration
);
// Report.off removes a given event handler if it exists.
report.off('loaded');
// Report.on will add an event handler which prints to Log window.
report.on('loaded', (event) => {
console.log('tile loaded...');
});
// Add a listener to 'error' events
report.on('error', (errorObject) => {
console.log(errorObject);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment