Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
Hi,
I am looking for a python/NodeJS based sample for embeddig dashboards in scenarios where app owns the data. I can only find C# based references in the documentation and samples.
Hi @infinitydlimit,
Here is similar thread in which some sample code that works for others is mentioned. Could you go to check if it helps in your scenario?
This works for me.
Reporting Class: Using single user access with app owns dataclass EmbedToken: def __init__(self, report_id, group_id, settings=None): self.username = 'USER' self.password = 'PASSWORD' self.client_id = 'CLIENT ID' self.report_id = report_id self.group_id = group_id if settings is None: self.settings = {'accessLevel': 'View', 'allowSaveAs': 'false'} else: self.settings = settings self.access_token = self.get_access_token() self.config = self.get_embed_token() def get_access_token(self): data = { 'grant_type': 'password', 'scope': 'openid', 'resource': r'https://analysis.windows.net/powerbi/api', 'client_id': self.client_id, 'username': self.username, 'password': self.password } response = requests.post('https://login.microsoftonline.com/common/oauth2/token', data=data) return response.json().get('access_token') def get_embed_token(self): dest = 'https://api.powerbi.com/v1.0/myorg/groups/' + self.group_id \ + '/reports/' + self.report_id + '/GenerateToken' embed_url = 'https://app.powerbi.com/reportEmbed?reportId=' \ + self.report_id + '&groupId=' + self.group_id headers = {'Authorization': 'Bearer ' + self.access_token} response = requests.post(dest, data=self.settings, headers=headers) self.token = response.json().get('token') return {'token': self.token, 'embed_url': embed_url, 'report_id': self.report_id} def get_report(self): headers = {'Authorization': 'Bearer ' + self.token} dest = 'https://app.powerbi.com/reportEmbed?reportId=' + self.report_id + \ '&groupId=' + self.group_id response = requests.get(dest, data=self.settings, headers=headers) return response
Django View
def index(request): ... irrelevant Code... conf = EmbedToken(report.get('report_id'), report.get('group_id')) token = conf.get_embed_token() return render(request, 'unfi_breakout/unfi_breakout.html', {'selectedReport': token.get('report_id'), 'embedToken': token.get('token')})HTML
{% extends extension %} {% load staticfiles %} {% block main %} <div id="reportContainer" style="height: 100% "> <script src="{% static 'PowerBi/dist/powerbi.js' %}"></script> <script> var models = window['powerbi-client'].models; var embedConfiguration = { type: 'report', id: '{{ selectedReport }}', embedUrl: 'https://app.powerbi.com/reportEmbed', tokenType: models.TokenType.Embed, accessToken: '{{ embedToken }}', settings: { filterPaneEnabled: false } }; var element = document.getElementById('reportContainer'); var report = powerbi.embed(element, embedConfiguration); </script> </div> </div> {% endblock %}
Regards
User | Count |
---|---|
10 | |
5 | |
4 | |
4 | |
3 |
User | Count |
---|---|
14 | |
9 | |
5 | |
5 | |
4 |