I promised a return to Spotfire API for IronPython posts, and that is finally happening. I had to get a few drafts cleared out, like 5 Ways to Approach Troubleshooting Data Problems, but now I’m back on track discussing how to change visualization titles with IronPython
In October last year, I committed to spending 100 hours learning IronPython. I wrote several “starter” IronPython posts, which can be found in the Data Shop Talk Archive. I have lost count of how much time I’ve spent on IronPython, but the clock starts again today.
My goals haven’t changed. They are still to ….
- Get an understanding of IronPython structure
- Develop an understanding of the Spotfire API
- Apply that understanding in Spotfire code examples
For the next several weeks, I’ll be using the code snippets posted on The Spotfire IronPython Quick Reference to explore the API. I’ll punctate that with an article here and there are the IronPython/Python structure as I go. Read on for this week’s code snippet.
This IronPython journey will start at the top of the tree on The Spotfire IronPython Quick Reference, which explains referencing visualizations. This code snippet shows you how to reference a visualization and change the title. It’s incredibly simple, with only one line of code.
Code Snippet 1
Note, MyVis is an object created by the developer. MyVis could be anything you want it to be. Because of that, you must also set it up as a parameter and map it to the visualization whose title you want to change. The ‘.Title’ piece is a reference to the API shown below.
.Title is a property of the Visual Class, which is part of the Spotfire.Dxp.Application namespace. It is used to get or set the title, which is exactly what we are doing. The visual class represents a visualization or a text area. If you want to modify a visualization, learn more about the visual class.
Code Snippet 2
Practically speaking, this isn’t terribly useful. To change the title, you must go into the code, which is actually harder than just double-clicking on the title to change it. To make it more useful, we can swap out the desired title (a string) with a connection to a property control.
In this second code snippet, I have incorporated an object called TitleInput that is mapped (via a parameter) to an input property control (also called TitleInput).
I mapped it to the property control as shown here.
Separately, I added a button and connected it to the script. Here’s what it looks like all together.
This was all pretty easy, although I will warn you I had issues with the parameter mapping dropping. I would map the parameters to the vis and the property control, only to see the mapping disappear later on. The code still worked, even if the mapping didn’t show up in the dialog. That concludes this post on how to change visualization titles with IronPython
Next week, I’ll keep working thru examples on the Spotfire IronPython Quick Reference.
Content created with Spotfire 10.2.
If You Enjoyed This
Check out a few of my other IronPython posts….