The Spotfire Community is moving to TIBCOmmunity and this forum location has closed. During the transition, you can still search the old forums but posting has been disabled. We encourage you to pick up the discussion at the new Spotfire community on TIBCOmmunity.
March 2010 - Posts - Tip of the Week

Tip of the Week

March 2010 - Posts

  • Using Script Controls to automate tasks in TIBCO Spotfire and TIBCO Spotfire Web Player

    The TIBCO Spotfire SDK allows developers to do three things: Automate, Extend, and Integrate. Automations allow us to automate common tasks and idioms inside TIBCO Spotfire Professional.  Extensions allow us to create extensions to the Spotfire platform, like new visualizations, new calculations, new panels, etc…Integrations allow us to integrate Spotfire Professional and/or the Spotfire Web Player into other applications and components.


    In TIBCO Spotfire version 3.1, TIBCO introduces the concept of Script Controls. Scripts Controls provide the ability to add IronPython scripts into a Text Area inside a Spotfire Analysis file. The script has access to the full Client API (from the SDK), and its goal is to perform common automation tasks. Its purpose is not to do or replace any extensions or integrations.   So, the next question is for automation, should I use the full SDK or should I use the Script Controls? There is some overlap, but there are a couple of key differences. 

    First, using the full SDK is for more powerful algorithms or automations which are meant to be used inside TIBCO Spotfire Professional or Enterprise Player only.  In these situations, you are usually displaying a dialog and adding capabilities to help out a Business Analyst or Author.  Using the Script Controls  is for when you want to do some lightweight automation, where you do not need a dialog, and you wish to have the solution work in all the TIBCO Spotfire Clients, including the Web Player. Therefore, the functionality created using the Script Controls typically will benefit the Business Author.

    The second important difference between the full Client APIs from the SDK (using C#) and Script Controls is that full extensions built using our C# API are built in the Spotfire application itself. This means it can work across and be available for any Spotfire document.  Script Controls, on the other hand, are built and stored inside a specific document.  If you wish to use them in multiple documents, you need to copy the script into each one.

    Let’s look at a two use cases to highlight the difference between the C# APIs and Script Controls. Assume you want to create a tool that acts as a template selection tool, which will provide the user with two lists: first a list of data tables, and then another list of templates to choose from. The tool will allow the user to select values from each list box and load and configure the appropriate document in Spotfire.  For this, you would use the full C# API to build a custom tool, which includes a dialog. This solution will not work  in the Web Player, as these types of changes should be done in the Professional Client and the tool is targeted at Business Analysts and Authors.

    Next , assume you created a document which includes a property control to define where to expose a vertical reference line in a Scatter Plot. You can have the user enter a number and have the reference line move to that location. But what if you wanted to allow the business user to toggle the reference line on or off? For this, properties will not work, but we can leverage Script Controls. 

    So how do you build such a Script? First, you need to turn on editing in a Text Area, and then select the Insert Action Control icon.  On the resulting Action Control dialog, choose to create a new script.


     
    Then , in the next dialog, give your Script  a name and enter the Script.


     

    Once you are done, click OK, and you are ready to use your script.


     
    For more information about Script Controls, including details of IronPython, how to use Properties as input and outputs to the Scripts, and best practices, please attend our 3.1 Delta Training or our dedicated course, Using Script Controls inside TIBCO Spotfire.

     


     

  • Using the Repeat Expression Function to Create Horizontal Bars

    We do not have a visualization which allows horizontal bars, however, you can create an expression which would create a pseudo horizontal bar in a Table based plot.  This is possible using the Repeat function available in TIBCO Spotfire version 3.1 for constructing an expression.

    Let’s assume we have the following data loaded in Spotfire:

     

    We can then create a calculated column using the following expression:
     

        Repeat(“█”,integer(10*[Col A]/Range([Col A])))

    The Repeat function allows you to repeat a string a specified amount of times.  For the string, we use the ASCII delete character, █.  To specify the number of times to repeat, you can use any calculation as long as it outputs an integer.

    In this example, we divide the value from Col A by the Range of Col A, then multiply by 10 and finally cast to an integer.

    The result?


  • Conditional Coloring to Highlight Top and Bottom Values

    In this week's post, we will introduce you to another excited new feature of TIBCO Spotfire 3.1, Conditional Coloring.  Let’s assume you have a Data Table which provides sales data for a particular store. The sales are broken up into three separate product categories: Furniture, Office Supplies, and Technology, and sales are measured across the different store locations per state.


    Let’s assume we want to highlight the top 5 sales result and the bottom 5 sales result for the combination of products and states. To do this, we can use TIBCO Spotfire’s Conditional Coloring to color the top 5 values green and the bottom 5 values red.


    We configure these settings inside the Color section of the Table’s Properties Dialog. First we create a Color Scheme Group that includes all the product columns: Furniture, Office Supplies, and Technology. We then add a Conditional Coloring rule, using the ‘Add Rule’ button and select the Top rule and set the value to 5 as shown below:


     
    This will then color the table so that the top 5 highest sales are colored green.

    As you can see, all 5 are from the office supplies column. What if we wanted to see the top 5 for each product? We then change the color scaling for this group to be by Column.


     
    The result now shows the top 5 sales in each product colored.

     

    We can now repeat this, but using the Bottom rule instead of Top to color the bottom 5 sales in each product red.

     


    Some of the additional benefits of using the Conditional Coloring Rules are that the coloring is updated to reflect the changes in the data , including filtering.  In addition, you can expose the values for top and bottom as Property Controls so that the business user can alter the values when desired.  


    In the screen shot below, you can see we exposed the top and bottom values as a slider control to let the user define how many values to color.

     

    More details on Conditional Coloring, including Color Schemes, Color Scaling, Using Expressions in Coloring, additional Conditional Coloring Rules, and other updates are discussed in detail in both the 3.1 Delta Training Course and the TIBCO Spotfire Business Author Bootcamp.

     

  • Predictive Analytics with TIBCO Spotfire and S+ or R

    Last week we discussed an important new concept in TIBCO Spotfire version 3.1, scenario analysis. This week we will continue learning about new 3.1 features by discussing another type of analytics: Predictive Analytics.

    With TIBCO Spotfire version 3.1, you can communicate directly with S+ or R to execute scripts and functions. You can then return the data back into Spotfire as rows, columns, tables, and even values to properties, like Document Properties, Data Table Properties, and Column Properties.

    For this example, we will be looking at interest rate differentials  (IRD) (http://www.investopedia.com/terms/i/interest-rate-differential.asp) for US and Canada from February 1976 to June 1996 and will try to calculate the IRD for future months.



     
    The first thing we need to do is to create a S+ or R script that will take the data in and will predict the IRD out 5 months.
    There are a variety of ways to do time series predictions: two of the common ones are Spline Analysis and the ARMA process (http://en.wikipedia.org/wiki/Time_series) For this tip we will use the ARMA process. If you would like additional information or training on other models, please consider taking our S+ or R training courses.

    To execute the S+ or R script in Spotfire we have to create a Data Function. A  Data Function is basically a S+ or R Script or Function that is stored in the Spotfire Library to be used in Spotfire analysis files.

    We create the Data Function by going to Tools > Register Data Functions and filling in the required information.  The first part is filling in the script itself:


     
    Then we need to define the input parameters. These are the expected inputs going into the script. In this case, we are going to expect the script to receive a Data Table.
     

    We then define the output via the output tab.  In this case, we are expecting the output to be a Data Table called result.

     

    When you are done, you click the Save button to save the Data Function in the Spotfire Library.

    Next, you need to add the Data Function into your document. To do this, you go to the Tools menu and click on the Data Functions tool and select the desired function.


     

    Once you click OK, you can now define what to send into the Data Function as inputs and what to send the output of the Data Function to. These are called Input and Output Handlers.
    The Input Handler will be both the date and Interest Ratio Differential columns from the Data Table.



     

    The Output Handler will be a new Data Table called result.


     


    Once we click OK, the calculation will occur and return a new Data Table called result, which includes the original date column, a value column for the Interest Rate Differentiator, and then a column called valueType which tells us if the row was an original row or a new, predicted row.


     
    We can then create a line chart showing the date on the x-axis and the average value on the y-axis and color by Value Type, so you can see the predicted months at the end.



     
    To take this example further, it is likely that a consumer may want to adjust how many months to predict. They may also want to adjust some variables in the algorithm. With TIBCO Spotfire 3.1, we can implement this by exposing variables like the length of prediction (in months) as properties where the consumer can pass in the value.


    See the example below, where the consumer set the number of months to predict to 3 and the result Data Table and Line Chart get updated to show 3 month’s predictions.


     

    If you would like more information on Data Functions and how to create them, please consider taking our 3.1 Delta Training Course SP1631  For more information on the specific algorithms and statistics we used, please consider taking our S+ or R training courses.

Syndication

Other Spotfire Blogs

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center