Saving Settings in Custom Visualizations

I had an interesting problem the other day while working on a custom visualization.  The requirement was for the user to be able to enter some custom text into a box to annotate some data, but the end usage was to export this to interactive PDF.  This meant that upon export, any text entered would be lost, so I needed a way to persist that data through the export.  Fortunately, Widget Properties will persist as defaults to the exported PDF, but it’s not a very good UI for the user to have to go to the property screen to enter some text that should just be editable directly on the Dashboard.  Fortunately, I discovered a way to save data to the property storage from outside of the property window and without adding any new GUI elements to the property window.  This turned out to save the day for my project!

For more information on how Widget Properties and saving works, read the full, “Integrating the Properties Viewer in your Widget“.  Basically, following the initialization of the appPropViewer from that code, you can invoke it directly at any time without the need for displaying the property window or even adding GUI elements.

To add a setting and save data to it’s shared storage, simply use the setProp() function and give it a Name of the property and and Value.  You can put nearly any object in here including Strings, Numbers and even Arrays.

appPropViewer.propertiesHelper.setProp("MyPropertyName", "MyValue");

After you’re finished setting properties, call the persistWidgetProps() method to force a save.  This is the same method that’s called when you click the OK button on the Properties window.

appPropViewer.persistWidgetProps();

And finally, to retrieve your data at any time, simply use the propertiesHelper and it’s appropriate get function.  There are several for whatever type of data you’ve stored in this property.  In this example, I stored a String:

appPropViewer.propertiesHelper.getString("MyPropertyName");

This trick opened up a lot of flexibility in my Visualizations that allows me to persist settings, states and values across both exports and setting default behaviors per Dashboard.

You may also like...