|
1 | | -# Power BI for HTML / JavaScript |
| 1 | +# powerbi-client |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +Install via Nuget: |
2 | 6 |
|
3 | | -## Install via Nuget |
4 | 7 | `Install-Package Microsoft.PowerBI.JavaScript -Pre` |
5 | 8 |
|
6 | | -## Install from NPM |
7 | | -`npm install powerbi-client` |
| 9 | +Install from NPM: |
| 10 | + |
| 11 | +`npm install -save powerbi-client` |
| 12 | + |
| 13 | +Install from Bower: |
| 14 | + |
| 15 | +`bower install powerbi-client --save` |
8 | 16 |
|
9 | | -## Install from Bower |
10 | | -`bower install powerbi-client` |
| 17 | +Installing beta versions: |
| 18 | + |
| 19 | +`npm install --save powerbi-client@beta` |
11 | 20 |
|
12 | 21 | ## Setup Power BI for embedding |
13 | | -Add the Power BI script include before your apps closing `</body>` tag |
| 22 | + |
| 23 | +Add the Power BI script before your apps closing `</body>` tag |
14 | 24 |
|
15 | 25 | `<script src="/bower_components/powerbi-client/dist/powerbi.js"></script>` |
16 | 26 |
|
17 | | -Add your access token to your app so it can be accessed. |
18 | | -*This can be set statically or dynamically via JavaScript.* |
| 27 | +This exposes two globals `Powerbi` which is the service class and `powerbi` which is an instance of the service. |
19 | 28 |
|
| 29 | + |
| 30 | +# Embedding |
| 31 | + |
| 32 | +## PaaS |
| 33 | +### When using PaaS model the tokens issued are for a specific report or tile and the token should be associated with the embed url on the same element to ensure each has a unique token allows embeding multiple reports using the same service instance. |
| 34 | + |
| 35 | +``` |
| 36 | +<div |
| 37 | + powerbi-type="report" |
| 38 | + powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=5dac7a4a-4452-46b3-99f6-a25915e0fe55" |
| 39 | + powerbi-access-token="eyJ0eXAiO...Qron7qYpY9MI" |
| 40 | +></div> |
| 41 | +``` |
| 42 | + |
| 43 | +## SaaS |
| 44 | +### When using SaaS model the tokens issued are for a specific user who can view many types of visuals. This means you can add this as a global token reused for all embeded visuals as shown below: |
20 | 45 | ``` |
21 | 46 | <script> |
22 | | - window.powerbi = window.powerbi || {}; |
23 | 47 | window.powerbi.accessToken = '{{AccessToken}}'; |
24 | 48 | </script> |
| 49 | +... |
| 50 | +
|
| 51 | +<div |
| 52 | + powerbi-type="report" |
| 53 | + powerbi-embed-url="https://embedded.powerbi.com/appTokenReportEmbed?reportId=5dac7a4a-4452-46b3-99f6-a25915e0fe55" |
| 54 | +></div> |
25 | 55 | ``` |
26 | | -# Embedding |
27 | | -Power BI will automatically search your apps DOM for Power BI embed components on page load. |
28 | | -If your app is dyanamically adding new embed components after page load you will need to manually initialize them via JavaScript. |
29 | 56 |
|
30 | | -## Setting the size of embedded components |
31 | | -The report will automatically be embedded based on the size of it's container. |
32 | | -To override the default size of the embeds simply add a CSS class attribute or inline styles for width & height. |
| 57 | +# Service Configuration |
33 | 58 |
|
34 | | -## Embed a Report into your app |
35 | | -Add the following markup to embed a Power BI Report |
| 59 | +As of 2.x Power BI will *NOT* automatically search your apps DOM for Power BI embed components on page load. |
| 60 | +If you need this behavior you need to configure the service by calling: |
36 | 61 |
|
37 | | -Embed via full qualified Report `EmbedUrl`. |
| 62 | +``` |
| 63 | +powerbi.enableAutoEmbed(); |
| 64 | +``` |
| 65 | +See: CHANGELOG.md for more details |
38 | 66 |
|
39 | | -`<div powerbi-embed="{{EmbedUrl}}" powerbi-report></div>` |
| 67 | +If your app is dyanamically adding new embed components after page load you will need to manually initialize them via JavaScript. |
40 | 68 |
|
41 | | -Or, embed with your `ReportId` |
| 69 | +# Embed configuration and other options |
42 | 70 |
|
43 | | -`<div powerbi-embed powerbi-report="{{ReportId}}"></div>` |
| 71 | +All configuration and options will be provided as attributes prefixed with `powerbi-options-` on the containing html element. |
44 | 72 |
|
45 | | -### Launch an embedded report in fullscreen mode |
| 73 | +1. **Filter Pane** |
| 74 | + |
| 75 | + FilterPane is enabled by default but can be disabled by adding the attribute: |
| 76 | + ``` |
| 77 | + <div ... powerbi-options-filter-pane-enabled="false"`></div> |
| 78 | + ``` |
| 79 | + |
| 80 | +## Setting the size of embedded components |
| 81 | +The report will automatically be embedded based on the size of it's container. |
| 82 | +To override the default size of the embeds simply add a CSS class attribute or inline styles for width & height. |
| 83 | + |
| 84 | +## Launch an embedded report in fullscreen mode |
| 85 | +(Assumes element with id `myReport` already contained embedded report) |
46 | 86 | ``` |
47 | 87 | <script> |
48 | | - var elem = document.getElementById('#myReport'); |
49 | | - var report = window.powerbi.get(elem); |
50 | | - |
| 88 | + var element = document.getElementById('#myReport'); |
| 89 | + var report = powerbi.get(element); |
| 90 | +
|
51 | 91 | report.fullscreen(); |
52 | 92 | </script> |
53 | 93 | ``` |
54 | 94 |
|
55 | 95 | ## Dynamically embedding components |
56 | 96 | ### Find all new Power BI components and initialize them. |
57 | | -You can optional pass a DOM element to scope the intialization |
| 97 | +`powerbi.init();` |
58 | 98 |
|
59 | | -`window.powerbi.init();` |
| 99 | +By default this will look for elements within the `document.body`; however you can pass optional DOM element to scope the intialization to smaller subset. |
| 100 | + |
| 101 | +``` |
| 102 | +var pageContainer = document.getElementsById('#pageContainer'); |
| 103 | +powerbi.init(pageContainer); |
| 104 | +``` |
60 | 105 |
|
61 | 106 | ### Embed a single component |
62 | 107 | Setup the a new DOM element with the same structure as above. |
63 | 108 | Call the `embed` function passing in the single element. |
64 | 109 |
|
65 | | -`window.powerbi.embed(element);` |
| 110 | +`powerbi.embed(element);` |
| 111 | + |
| 112 | +In the case above, the embed url, access-token, type, options, etc will be determined from the elements' attributes. |
| 113 | +You can optionally pass a second argument to embed specifying these values as an object: |
| 114 | + |
| 115 | +`powerbi.embed(element, { embedUrl: '...', accessToken: '...' }`; |
66 | 116 |
|
67 | 117 | ### Get a reference to a existing Power BI component |
68 | | -Returns an instance of the Power BI component associated with an element |
| 118 | +Retrieve the existing component associated with the element. |
| 119 | + |
| 120 | +`var myPowerBIComponent = powerbi.get(element);` |
69 | 121 |
|
70 | | -`var myPowerBIComponent = window.powerbi.get(element);` |
|
0 commit comments