Blog or Video
It would be really awesome if we could use data from columns to update visualization titles or even custom expressions, but we can’t. However, we can update titles with a value from Document Properties. That means, we just need to calculate the desired value and pass it to a document property.
My code creates an object called “today” to store the system time. Note, the Spotfire data function framework always returns the result from a call to Sys.time() with DateTime. This means, you must write the result to a document property that is DateTime. In my first attempt, the document property was a Date, and that failed. I confirmed this with Spotfire support.
Next, I create two more objects called “TwoDayLag” and “OneDayLag” to store my calculated values. The values are generated by subtracting two days and one day, respectively, from the “today” object.
The Difftime function calculates the difference in time between two dates or date time objects. However, in this case, I wanted to subtract two days from a single date time object, so I used as.difftime. You can read about difftime here.
And here is a version for easy copy and paste.
today <- Sys.time() TwoDayLag <- today - as.difftime(2, unit = "days") OneDayLag <- today - as.difftime(2, unit = "days")
The Data Function
This data function doesn’t need input parameters, just two output parameters as shown below.
When the data function runs, you map the Output to the document property.
Here are the details steps for you to replicate my work.
- Before creating the data function, go to the File menu. Select Document Properties.
- Go to the Properties tab. Click the New button.
- Name the document property. Set the Data type to DateTime. You must set the data type to DateTime, not Date. Click Ok.
- Go to Data menu. Select Data Function Properties.
- Click the Register New button.
- Name the data function.
- Make sure R script – TIBCO Enterprise Runtime for R is chosen in the Type: dropdown.
- Copy and paste the script.
- Go to the Output Parameters tab, and add the two output parameters as shown in the screenshot above. They should be Value type.
- Upon saving the data function, you will be prompted to map the parameters.
- Connect the output parameters to the document properties.
Connecting the Document Property to a Visualization
To connect the document property to a visualization….
- Go to Properties for the visualization.
- Go to the General menu.
- Click the Edit button
- Find the document property and insert it in the expression.
And now you know how to use TERR to dynamically update visualization titles. Not only is this skill useful in titles, but you’ll find uses for it anywhere document properties are used.
Content created with Spotfire 10.3.