Using Scripts in the Text Area


You can define your own scripts in TIBCO Spotfire by adding action controls in a text area. The scripts are written in IronPython and they allow you to incorporate simple actions or tools into your analysis without having to deploy complete AddIns to the server. The scripts have full access to the Spotfire API.

To be able to create analyses containing IronPython scripts, you need to belong to the group "Script Author" and have the license function “Author Scripts” under “TIBCO Spotfire Extensions” enabled. Select Tools > Administration Manager to make the necessary changes, or contact your Spotfire Administrator to do it for you.

In HTML mode you can also add JavaScript. See Details on Insert JavaScript and JavaScript Example Scripts for more information.

  1. Click on the Toggle Edit Mode button, text_toggle_edit_mode_button.png, in the Text Area title bar.

  2. Click on the Insert Action Control button, text_icon_action.png.

    Response: The Action Control dialog is displayed.

  3. Click on Script in the left-hand panel.

  4. Type a Display text to be shown in the text area.

  5. Select a Control type: Link or Button.

  6. In the Available scripts list, click on the script of interest.

    Comment: To define a new script, see Example scripts below.

  7. Click on each parameter (if there are any) in the Necessary input for the selected script field and specify the Input for the selected parameter.

    Comment: If the script needs some kind of input values, then these must be specified before the script can be executed. Examples of input could be a text value or a specification of a visualization or a page to work with.

  8. When all script parameters have been defined, click OK.

    Response: The action control is added to the text area.

  9. Click on the Toggle Edit Mode button, text_toggle_edit_mode_button.png, in the text area title bar to turn off the Edit mode.

Example scripts:

Below are more details about how to create and use a few example scripts in TIBCO Spotfire. These steps can also serve as instructions for how you should work when creating your own scripts.

  1. In a text area in Edit mode, click on the Insert Action Control button, text_icon_action.png.

    Response: The Action Control dialog is displayed.

  2. Click on Script in the left-hand panel.

  3. Click New....

    Response: The New Script dialog is displayed.

  4. Type the Script name: Change visualization title.

  5. In the Script field, type or paste your script:

    visual.Title = title

  6. Click Add....

    Comment: You need to specify the type of the parameters used in the script.

    Response: The Add Script Parameter dialog is displayed.

  7. In the Name field, type title.

    Comment: This is the string parameter containing the visualization title.

  8. From the Type drop-down list, select String.

    Comment: The title must be a string which can be defined either by a simple text value, a string property or an expression.

  9. If desired, add a Debug value which can be used for testing the script.

  10. Click OK.

    Response: The "title" parameter is added to the Script parameters list.

  11. Click Add... again, to define the second parameter.

    Response: The Add Script Parameter dialog is displayed.

  12. In the Name field, type visual and select Visualization as the Type.

    Comment: This parameter is used to point out which visualization to change the title on.

  13. Select a Debug value visualization to use when testing the script.

  14. Click OK.

    Response: The "visual" parameter is added to the Script parameters list.

  15. If desired, test the script by clicking Run Script.

    Response: The selected visualization title is updated with the Debug value provided in the Add Script Parameter dialog. Click Undo in the New Script dialog to revert to the old title.

  16. Click OK to close the New Script dialog.

    Response: The script is added to the Available scripts list in the Action Control dialog and the defined parameters are shown in the Necessary input for the selected script list (as long as the script is selected in the Available scripts list).

  17. Continue with To use the "Change visualization title" script below.

Tip: To change the title of the active visualization, use the following script:

Document.ActiveVisualReference.Title = title

  1. Define a display text and a control type as described in "To add a script action link or button to the text area".

  2. Make sure that the "Change visualization title" script is selected.

  3. Click on the first parameter, title, in the Necessary input for the selected script list.

    Response: The Input for the selected parameter settings for title become available.

  4. Determine whether to define the title using a predefined Value, a Property or an Expression.

    Comment: In this example, we will assume that the title is specified using a Property.

  5. Click Select Property....

    Response: The Select Property dialog is displayed.

  6. On the Document Property tab, click New....

    Comment: If a suitable property is already available, you can select it in the list and go to step 10.

    Response: The New Property dialog is displayed.

  7. Type a suitable Property name, for example, visualization.title.

  8. From the Data type drop-down list, select String.

    Comment: The title must be a string.

  9. Type a Value to be the first (default) value of the property. For example, My Visualization Title.

  10. Click OK.

    Response: The new property is selected in the Select Property dialog.

  11. Click OK.

    Response: The Property field in the Action Control dialog is updated to show the expression syntax for the property you just defined.

  12. Click OK.

    Response: The action control is added to the text area.

  13. Click on the Toggle Edit Mode button, text_toggle_edit_mode_button.png, in the text area title bar, to turn off the Edit mode.

  14. Test the action control by clicking on it in the text area.

The property controlling the visualization title could in turn be modified using a property control (for example, an input field) in the text area. See Using Properties in the Analysis for examples of how you can add property controls.

text_my_visualization_title_input_field.png

 

text_change_title_button.png

  1. In a text area, click on the Insert Action Control button.

    Response: The Action Control dialog is displayed.

  2. Click on Script in the left-hand panel.

  3. Click New....

    Response: The New Script dialog is displayed.

  4. Type the Script name: Change filtering scheme.

  5. In the Script field, type or paste your script:

    from Spotfire.Dxp.Application.Filters import FilterPanel

    # Get hold of the filters panel for the current page.
    panels = Document.ActivePageReference.Panels
    # The return value and out parameters are returned as a tuple
    # in IronPython and can be bound with pattern matching.
    (found, filterPanel) = panels.TryGetPanel[FilterPanel]()

    # Find the filtering selection named "Filters2"
    # and set it as current.
    for filteringScheme in Document.FilteringSchemes:
       filteringSelection = filteringScheme.FilteringSelectionReference
       if filteringSelection.Name == "Filters2":
           filterPanel.FilteringSchemeReference = filteringScheme

    Comment: The included example script expects to find a filtering scheme called "Filters2" and changes the filtering scheme of the active page to the Filters2 filtering scheme.

  6. Click OK to close the New Script dialog.

    Response: The script is added to the Available scripts list in the Action Control dialog.

  7. Continue with To use the "Change filtering scheme" script below.

  1. Define a display text and a control type as described in To add a script action link or button to the text area above.

  2. Make sure that the Change filtering scheme script is selected.

  3. Click OK.

    Response: The action control is added to the text area.

    Comment: This script requires no input from the end users, but if there is no "Filters2" filtering scheme in the analysis, then nothing will happen when the action control is clicked.

  4. Click on the Toggle Edit Mode button, text_toggle_edit_mode_button.png, in the Text Area title bar, to turn off the Edit mode.

  5. Test the action control by clicking on it in the text area.

text_change_filtering_button.png

See also:

IronPython Example Scripts

How to Use the Text Area