Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction


The SAP Analytics Cloud (SAC) Custom Widget framework offers an exciting opportunity for developers to extend the existing set of widgets with their custom creations. This can be particularly useful when a specific user interface element, data visualization, or functionality required within a dashboard is not available in the predefined set of widgets. In this blog post, we'll explore our experiences using OpenAI's ChatGPT to create custom widgets for SAP Analytics Cloud and share some tips that we've discovered along the way. We'll also include a demo recording showcasing the process, as shown below:


The Technical Foundation


Custom widgets in SAC are implemented as Web Components, a suite of technologies that allows developers to create reusable custom elements with encapsulated functionality. This makes it easy to integrate them into web apps without interfering with the rest of your code. When using ChatGPT to create custom widgets for SAC, it's essential to ensure that it generates Web Components, as they form the technical foundation for the custom widget.

Request ChatGPT to develop a Web Component using prompts such as these:

1. Design a Web Component for a news ticker that includes multiple labels, a 30-second duration, a 48px font size, and a red highlight when the mouse hovers over the labels.

2. Develop a Web Component that displays a line chart with both x and y axes.

3. Create a Web Component that renders a line chart with x and y axes, without using any external charting libraries.

Here is an elaboration on the structure of custom widgets:

The dark green widgets are required, while the light green ones are optional. The JSON file serves as a declaration file for the widget. Additionally, the JavaScript file (main.js) houses the widget's business logic. As a Web Component, ChatGPT can assist in generating this element.


 

Our Approach



  1. Utilizing ChatGPT (GPT-4) for creating web components. By asking ChatGPT specific questions, we can generate web components that can be used in SAP Analytics Cloud.

  2. Employing a code template to wrap the generated web components into custom widgets for use in SAP Analytics Cloud.


Github link is here.

The code template comprises the essential JSON file and main.js required for a custom widget.

Copy and paste the web component generated by ChatGPT into the main.js file.

Ensure that the tag name in the JSON file matches the name in the web component.

For instance:

In the JSON file, you'll find the following:
"tag": "news-ticker",

Ensure that the "news-ticker" tag corresponds to the one used in main.js.
customElements.define('news-ticker', NewsTicker)

Replace the placeholder URL with the precise URL of the main.js. If you want to use SAC hosting service, refer to blog: https://blogs.sap.com/2023/04/13/hosting-and-uploading-custom-widgets-resource-files-into-sap-analyt...
"url": "http://localhost:3000/gpt/news-ticker/main.js",

3. Implement business logic by the developer, such as interpreting the SAC data model into a structure that the custom widget can accept.

Tips From Our Experience


1. ChatGPT also generates an HTML file to test the Web Component. It's beneficial to test it with this HTML file before wrapping it as a custom widget.
2. ChatGPT may generate multiple versions of implementations. Choose the best one that suits your needs.
3. Make your questions to ChatGPT as specific as possible to get the most accurate results.

Additional Tips:

4. Break down complex requirements into smaller, more manageable tasks when asking ChatGPT for assistance.
5. Continuously test and iterate the generated code to ensure it meets the desired functionality and adheres to best practices.

Conclusion


Using ChatGPT to create custom widgets for SAP Analytics Cloud offers significant benefits, such as time savings and rapid prototyping.

However, it's important to note that ChatGPT is a helpful tool but cannot replace a developer's experience. It's essential for developers to enhance the generated code with their expertise and ensure the custom widget meets the desired functionality and quality standards.

As AI-powered tools like ChatGPT continue to evolve, we can expect even greater efficiency and assistance in the development process. However, the collaboration between human expertise and AI will remain crucial for creating high-quality custom widgets for SAP Analytics Cloud.

 

Disclaimer:
SAP notes that posts about potential uses of generative AI and large language models are merely the individual poster's ideas and opinions, and do not represent SAP's official position or future development roadmap. SAP has no legal obligation or other commitment to pursue any course of business, or develop or release any functionality, mentioned in any post or related content on this website
1 Comment