Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Last active October 5, 2018 11:41
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/1392403aa328684738e4ed6f0b8a664f to your computer and use it in GitHub Desktop.
Save krishnaanaril/1392403aa328684738e4ed6f0b8a664f to your computer and use it in GitHub Desktop.
Embed Power BI dashboard for organization
// get access token
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).subscribe(res=>{
// select first among available dashboards
this.getDashboard(res["value"][0]["id"], res["value"][0]["embedUrl"]);
});
});
}
getDashboard(id: string, embedUrl: string){
var embedConfiguration = {
type: 'dashboard',
id: id,
embedUrl: embedUrl,
tokenType: pbi.models.TokenType.Aad,
accessToken: this.adalSrv.context.getCachedToken(environment.powerBIEndpoint)
};
// Grab the reference to the div HTML element that will host the report.
const dashboardContainer = <HTMLElement>document.getElementById(
'embedDashboard'
);
const report = this.powerbi.embed(
dashboardContainer,
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('dashboard 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