I’m trying to embed an Apache 1.5 dashboard in a WordPress site. So far I’ve succeeded in doing the following:
- Upgrade to Apache Superset 1.5 and enable the embedded dashboard functionality
- Configure dashboard to be embedded
- Implemented backend code to obtain JWT token
What I’m struggling with now is to implement the "@superset-ui/embedded-sdk" functionality in my WordPress site (using TwentyTwentyOne standard template). I’m trying to follow the instructions listed here: https://fossies.org/dox/apache-superset-1.5.0-source/md_superset_embedded_sdk_README.html
The CDN approach looks the easiest, but I’m getting the error ReferenceError: Buffer is not defined. And if I add the following code:
<script src="https://unpkg.com/buffer"></script>
Then I get the error ReferenceError: require is not defined. I’m not sure how I can resolve this error. Is the CDN approach a dead end, or is there a way I can make this work?
With the "Using npm" approach I’m struggling even more. I’m able to install the npm packages on bitnami linux, but then I don’t know how to make use of them in the site. I wasn’t able to make it work to add ‘@superset-ui/embedded-sdk’ using wp_enqueue_script(). Also I tried the following code in wordpress:
<script type="module">
import {embedDashboard} from 'http://[MY_IP_ADDRESS]/wp-content/themes/twentytwentyone/node_modules/@superset-ui/embedded-sdk/lib/index.js';
</script>
However then I get the following error:
Uncaught SyntaxError: The requested module ‘http://[MY_IP_ADDRESS]/wp-content/themes/twentytwentyone/node_modules/@superset-ui/embedded-sdk/lib/index.js’ does not provide an export named ’embedDashboard’
I don’t quite understand this error as embedDashboard does appear to be defined in the js file. I also tried using the embedded-sdk/bundle/index.js file with the same result.
I’ve spent many hours on this and I’m not sure what approach I should take. Can anyone point me in the right direction? Or even better: have a solution to a similar problem with sample code I can look at? If I need to provide more details on what I’ve tried or what errors I’m seeing let me know.
2
Answers
Hello, I hope this example of using ‘superset embedded-sdk’ will help you:
This is how I did it.
I wrote my backend in Flask.
My Superset Version is 2.0
backend.py
Explanation:
The Major part of understanding is the Guest_Token Function.
Here two POST Requests are at play.
Payload for Guest_Token:
Explanation:
The Payload is a JSON with 3 Key-Value Pair.
I ran my backend on Localhost:5000.
For Frontend, I created a directory "templates" and put my index.html file inside it.
index.html
Explanation:
It calls my guest-token method which returns a Guest-Token to my frontend. The Frontend then makes a request to Superset Embed Dashboard URL with the guest-token which in turn embeds and renders the chart in an Iframe on my website.