Category: Spotfire Tricks

IronPython to reset all tags

For a recent project, we wanted the user of a Spotfire template to be able to reset all the tags, including both built-in tags and tags the user may have added, with a single click.

One solution is to use an IronPython script to reset each tag collection in the template, keeping in mind that, if we hard-code the names of the tags to reset, we won’t be able to handle cases where users have added custom tags. In order to reset tags that may be added later on, we can use Spotfire’s IronPython API to identify and reset tag columns on the fly.

Here is what the code looks like in Spotfire:

And in more copy/paste-friendly format:

from Spotfire.Dxp.Data import *
from System import Array

for table in Document.Data.Tables:
    for column in table.Columns:
        if str(column.Properties.ColumnType) == “Tags”:
            tagCollectionName = column.Properties.Name
            tagColumn = column.As[TagsColumn]()
            tagNames = Array[str](tagColumn.TagValues)
            currentTable.Columns.Remove(column)
            currentTable.Columns.AddTagsColumn(tagCollectionName,tagNames)

Notes on the code:

This script loops over all the tables in the Spotfire analysis and checks the type of each column. When we locate a tags column, we extract the name of the tag collection, as well as any associated tags, drop the column from the data table, and create the tags collection anew. We can use this approach to reset all tags with one command because, by default, all datapoints are untagged when a “new” tag collection is created. The script will reset all tags in the analysis, including custom tags added by the user, and it will simply exit quietly if there are no tags. There are no input/output parameters for this script, but we could use input parameters to apply the same tag-resetting logic to a specific subset of the data.

Spotfire Version

Content created with Spotfire 7.12

Data Science Intern at Ruths.ai and  Applied Physics PhD candidate at Rice University

How to Pass Marked Data into a Document Property

Consider this scenario, you have a calculation that necessitates the ability to pull a value from marked data. This is a complicated feedback system.

Setup the components

First, let’s setup the moving parts:

  • Create a document property ${sumMarkedRows}. This is going to be the document property that we’ll use in our calculation.
  • Created a text area. We need this so that our JavaScript can pass the data to the document property.
  • In the text area, add a Calculated value that is Sum([Column]).
  • Pick a marking layer that will facilitate this connection.

Connect the parts

Next we’ll need to pass that data from the marked layer to the calculated value to the JavaScript to the document property. What a mouthful!

  1. Create an input field for ${sumMarkedRows}
  2. Create a JavaScript that is called when the calculated value changes so we can pass it to the document property:

    <script>
    $(‘theIDoftheSpotfireCalcValue’).on(‘DOMSubtreeModified’,function(){
    $(‘theIDoftheInputfield’).text($(‘theIDoftheSpotfireCalcValue’).text());
    $(‘theIDoftheInputfield’).blur();
    })
    </script>

  3. That script needs the IDs swapped out then you can put it in the HTML area of that text area.
  4. Use ${sumMarkedRows} in your calculated column as the value that changes
  5. Wrap all of that with <div style=”display:none”>   …all the html…  </div> to hide that trickery

Technical Director at Ruths.ai

A Different Way to Build Drop-Down Property Controls

  • Does adding new columns to a data table “contaminate” your drop down property controls?
  • Would you prefer to not have to create column properties for drop-down controls in addition to the document property?
  • Would you like to learn a property control hack?

Read More

Guest Spotfire blogger residing in Whitefish, MT.  Working for SM Energy’s Advanced Analytics and Emerging Technology team!

How do you set colors in Spotfire without reverting back to defaults?

  • Would you like to “set” colors to be applied to all visualizations in a DXP?
  • Have you set the colors for each unique value in a column but find the colors get reset to the default?
  • Are you using property controls to change the Color By variable?

Read More

Guest Spotfire blogger residing in Whitefish, MT.  Working for SM Energy’s Advanced Analytics and Emerging Technology team!

Spotfire:  Using Document Properties to Reverse a Color Scheme Based on Desired Outcome

Have you ever wanted to reverse a Spotfire visualization color theme based on whether an outcome is desired or not?

For example, positive production almost always equates to a desired outcome while one might want to see CAPEX decrease.  If switching between the two options in a visualization via a Document Property, we might want to indicated a desired outcome as green and an undesired outcome as red rather than simply designating positive numbers as green and negative numbers as red.

Today, we will show you how to use a document property to create a switch, which will then alter the color scheme to denote whether an outcome is desired or undesired rather than positive or negative.

Read More

Jason is a Junior Data Scientist at Ruths.ai with a Master’s degree in Predictive Analytics and Data Science from Northwestern University. He has experience with a multitude of machine learning techniques such as Random Forest, Neural Nets, and Hidden Markov Models. With a previous Master’s in Creative Writing, Jason is a fervent believer in the Oxford comma.

Keeping Spotfire Visualizations Working when Replacing Data by Using Column Properties

Do you ever try to replace data in a Spotfire dxp only to find many of the visualizations no longer work?

At Ruths.ai, we create Spotfire templates as one of our main products.  Often, people have to replace our source data with their own to utilize our templates.  However, this can cause some complications when they match columns with different names than the ones in our source data.  Ideally, people would like to keep their column names because the names have business implications. Yet, when that column name has been hard coded into a Spotfire expression, a visualization, calculated column, or data limiting expression could break.

Until now.

In this post, we will demonstrate how to use column properties to ensure that expressions will remain intact in a Spotfire dxp even after changing a column name when replacing data.    

Read More

Jason is a Junior Data Scientist at Ruths.ai with a Master’s degree in Predictive Analytics and Data Science from Northwestern University. He has experience with a multitude of machine learning techniques such as Random Forest, Neural Nets, and Hidden Markov Models. With a previous Master’s in Creative Writing, Jason is a fervent believer in the Oxford comma.

“Whiting Out” a Visualization Label in Spotfire

When using Spotfire, do you ever place a variable on an axis to make the visualization look a certain way, only to see its label show up unwanted next to the other necessary labels?

I’ve had this happen when manipulating dates or forcing a visualization (scatter plot, waterfall chart, bar chart) to be in a certain rank order.  Recently, I wrote a post on how to rank and order a gantt chart, which faced this issue.  I discussed how to remedy the issue in that article, but here I want to highlight the method used since we can use it in many other scenarios.

In this post, we will discuss how to white out a label on an axis.

Read More

Jason is a Junior Data Scientist at Ruths.ai with a Master’s degree in Predictive Analytics and Data Science from Northwestern University. He has experience with a multitude of machine learning techniques such as Random Forest, Neural Nets, and Hidden Markov Models. With a previous Master’s in Creative Writing, Jason is a fervent believer in the Oxford comma.

Exporting Spotfire to PDF with Action Control Button

Recent Spotfire versions include the ability to export visualizations, pages, or the entire analysis into a PDF from the File menu or even with an Action Control button.  Finally!  Version 7.12 includes extremely user friendly customization options while previous versions require some IronPython code:  we will address both here.

The 7.12 version gives the user an interface for customization that we could previously only access via IronPython.  Spotfire has delivered what many users for years have clamored for, so check it out after the break…

Read More

Jason is a Junior Data Scientist at Ruths.ai with a Master’s degree in Predictive Analytics and Data Science from Northwestern University. He has experience with a multitude of machine learning techniques such as Random Forest, Neural Nets, and Hidden Markov Models. With a previous Master’s in Creative Writing, Jason is a fervent believer in the Oxford comma.

How to insert a live Spotfire in a PowerPoint

I’m embarrassed to say that I have telling people this wasn’t possible for the longest time but turns out, the Office Add-ins store had a plugin for HTML code in PowerPoint.

Setting up the Add-on

Go into PowerPoint, and from the top select Store. This opens the Office Add-ins for PowerPoint:

Search for HTML and select Office Apps Fiddle for PowerPoint.

Adding the script

Drop in your new add-in and select HTML.

Use the code listed here and replace it with the link to your Spotfire file. Serious caveat: You will need to log into the server every time, but that can simply be prep for your meeting.

Finished! The web player will be interactive inside the PowerPoint and works great. This presentation will stay current with your live data.

For some further improvements, you can use JavaScript mashup to integrate it a little better.

Regards,

Lucas

Technical Director at Ruths.ai