Last active
October 5, 2018 11:41
-
-
Save krishnaanaril/1392403aa328684738e4ed6f0b8a664f to your computer and use it in GitHub Desktop.
Embed Power BI dashboard for organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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