Local Storage API

With the local storage API, you can store data in the browser's local storage. To use the local storage API, the customer's local storage admin switch has to be enabled.

Local storage is isolated so that each type of visual has its own separate storage access.

Note

It’s developer’s responsibility to ensure that the stored data conforms to the consumer’s organizational policies, and to inform users about what information is stored, if the sensitivity of the data requires it. In particular, custom visual developers should encrypt the data if business goals or scenarios expect it.

How to use local storage

This version of the local storage API is scheduled for deprecation. We're not accepting any more requests. When possible, use Version 2.

In the following example, a counter is increased whenever the update method is called. The counter value is saved locally and called each time the visual starts. This way, the counter continues counting from where it left off instead of starting over each time the visual is started:

export class Visual implements IVisual {
        // ...
        private updateCountName: string = 'updateCount';
        private updateCount: number;
        private storage: ILocalVisualStorageService;
        // ...

        constructor(options: VisualConstructorOptions) {
            // ...
            this.storage = options.host.storageService;
            // ...

            this.storage.get(this.updateCountName).then(count =>
            {
                this.updateCount = +count;
            })
            .catch(() =>
            {
                this.updateCount = 0;
                this.storage.set(this.updateCountName, this.updateCount.toString());
            });
            // ...
        }

        public update(options: VisualUpdateOptions) {
            // ...
            this.updateCount++;
            this.storage.set(this.updateCountName, this.updateCount.toString());
            // ...
        }
}

Considerations and limitations

  • The local storage limit is 1 mb per GUID.
  • Data can be shared between visuals with the same GUID only.
  • Data can't be shared with another instance of Power BI Desktop.
  • The local storage API isn't activated by default. To activate it for your Power BI visual, send a request to Power BI visuals support, pbicvsupport@microsoft.com.
  • The local storage API doesn't support await constructions. Only then and catch methods are allowed.

Your visual should be available in AppSource and be certified.