Published
Edited
Mar 5, 2020
2 stars
Insert cell
Insert cell
Insert cell
viewof clientId = storedText({"key": "pbi.clientId"})
Insert cell
viewof reportId = storedText({"key": "pbi.reportId"})
Insert cell
viewof dataSetId = storedText({"key": "pbi.datasetId"})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
msalConfig = ({
auth: {
clientId: clientId,
authority: "https://login.microsoftonline.com/organizations",
//redirectURI: "http://localhost:8087"
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
});

Insert cell
Insert cell
myMSALObj = new msal.UserAgentApplication(msalConfig);
Insert cell
Insert cell
Insert cell
Insert cell
accessToken = {
const tokenRequest = {
scopes: [ "https://analysis.windows.net/powerbi/api/App.Read.All"]
};
return new Promise((resolve, reject) => {
myMSALObj.acquireTokenSilent(tokenRequest)
.then(response => {
mutable userName = response.account.name;
resolve(response.accessToken)
})
.catch(err => reject(err))
})
}
Insert cell
Insert cell
Insert cell
Insert cell
reportsAndDatasets = ({
"datasets": [
{
"id": dataSetId
}
],
"reports": [
{
"id": reportId
}
]
})
Insert cell
Insert cell
generateTokenResponse = d3.json('https://api.powerbi.com/v1.0/myorg/GenerateToken', {
method:"POST",
body: JSON.stringify(reportsAndDatasets),
headers: {
"Content-type": "application/json; charset=UTF-8",
"Authorization": `Bearer ${accessToken}`
}
})
Insert cell
Insert cell
Insert cell
reportConfig = ({
type: 'report',
tokenType: pbi.models.TokenType.Embed,
accessToken: embeddedToken,
embedUrl: "https://app.powerbi.com/reportEmbed",
id: reportId,
permissions: pbi.models.Permissions.All,
viewMode: pbi.models.ViewMode.Edit,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: false,
pageView: "fitToWidth", // "actualSize",
/* Uncomment if you require a custom layout
layoutType: models.LayoutType.Custom,
customLayout: {
pageSize: {
type: models.PageSizeType.Custom,
width: 1500,
height: 1200
},
}
*/

}
})

Insert cell
Insert cell
report = window.powerbi.embed(elReport, reportConfig);
Insert cell
Insert cell
filters = [
{
"$schema":"http://powerbi.com/product/schema#basic",
"target":{"table":"Detailed Metrics 1","column":"Sub Category"},
"filterType":1,"operator":"In",
"values":subcategories,
"requireSingleSelection":false
}
]

Insert cell
report.setFilters(filters)
Insert cell
md`# Obtaining clientId, reportId & datasetId`
Insert cell
md`## ClientId
We need to register an App in Azure Portal (or

* CReate a new APplication (NAtive)
* In Azure Portal: allow implicit flow (in manifest)
* Confifure Web redirect URI
* Configure API permision Directory.AccessAsUser.All`
Insert cell
Insert cell
Insert cell
window.location.href

Insert cell
Insert cell
style_bootstrap
Insert cell
import {style_bootstrap, storedText} from "@elaval/utils"
Insert cell
import {checkbox, button} from "@jashkenas/inputs"

Insert cell
pbi = require('powerbi-client@2.8.0/dist/powerbi.js')
Insert cell
msal = require('msal@1.2.1/dist/msal.js')
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more