Use TERR to Dynamically Update Visualization Titles

This week, I worked with our production team to create a downtime dashboard. The dashboard only brings in allocated data, which has a two-day lag. It makes sense to include the date of the most recent data in the visualization title. This task can be accomplished with TERR, JavaScript, or Python. I chose TERR for my project, so this post will show you how to use TERR to dynamically update visualization titles.

Blog or Video

Dynamic Titles

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.

This task can be accomplished in TERR or Python data functions. I’ve also done it in JavaScript, but JavaScript can require a trigger. Both TERR and Python data functions run when the file opens, so I went with TERR.

The Script

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.

Detailed Steps

Here are the details steps for you to replicate my work.

  1. Before creating the data function, go to the File menu. Select Document Properties.
  2. Go to the Properties tab. Click the New button.
  3. Name the document property. Set the Data type to DateTime. You must set the data type to DateTime, not Date. Click Ok.
  4. Go to Data menu. Select Data Function Properties.
  5. Click the Register New button.
  6. Name the data function.
  7. Make sure R script – TIBCO Enterprise Runtime for R is chosen in the Type: dropdown.
  8. Copy and paste the script.
  9. Go to the Output Parameters tab, and add the two output parameters as shown in the screenshot above. They should be Value type.
  10. Upon saving the data function, you will be prompted to map the parameters.
  11. Connect the output parameters to the document properties.

Connecting the Document Property to a Visualization

To connect the document property to a visualization….

  1. Go to Properties for the visualization.
  2. Go to the General menu.
  3. Click the Edit button
  4. 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.

Spotfire Version

Content created with Spotfire 10.3.

Check Out My Most Recent Posts

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.