Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Created October 5, 2018 09:54
Show Gist options
  • Save krishnaanaril/1020ba7e54dfef79bfbdb4fdec266d4d to your computer and use it in GitHub Desktop.
Save krishnaanaril/1020ba7e54dfef79bfbdb4fdec266d4d to your computer and use it in GitHub Desktop.
Embedding Power BI Dashboard for customers
embedPowerBIDashboard() {
this.service.getDashboardEmbedToken().subscribe((res) => {
let response = res.json();
let Token = response.EmbedToken;
const config = {
type: 'dashboard',
tokenType: pbi.models.TokenType.Embed,
id: response.Id,
embedUrl: response.EmbedUrl,
accessToken: Token.token,
};
// 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,
config
);
// 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('loaded: '+event);
this.setTokenExpirationListener(Token.expiration,
2 /*minutes before expiration*/);
})
report.on('error', function (event) {
console.log(event.detail);
report.off('error');
});
},
(error) => {
console.log(error);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment