Jump to content
  • IronPython Checkbox and Radio Buttons Property Control for Spotfire


    Extend the possibilities of Property Controls by creating Checkboxes and Radio Buttons to control Document Properties

    Introduction

    Property controls are a way to control document properties through input elements. Think of document properties are variables that can be used almost everywhere in your analysis. For example, you can set a document property to manipulate the output of a calculated column, be part of a data function input parameter, or part of a custom expression. They can also be used as parameters to retrieve data on-demand or trigger a script when the document property changes to automate a set of actions.

    Spotfire provides a set of powerful ways to control document properties through input fields, dropdowns, list boxes and sliders. These are called Property Controls in TIBCO Spotfire, but there are  no check-boxes or radio buttons available out of the box as of yet. However we can easily create them with out of the box features

    .

    checkbox.gif.e8cca9a297cae97e7ef46b75e96a731d.gif

     

    Requirements

    To create radio buttons or checkbox property controls, we need:

    1. A Boolean Document Property and optionally a script to run when this document property changes

    2. A Calculated value that uses the Boolean Document Property as the custom expression and a script to change the state of the Boolean Document Property state.

    For example, if we want to create a a checkbox that turns on or off the visualization gridlines, you create a "showGrids" Boolean document property and attach a script so when the document property changes, it triggers the script. Now we need another way change the Boolean document property. This can be done by using a calculated value that triggers the script that toggles the Boolean document property

    checkbox.png.ee32a68f2a22b1e0842fdf16726ca7c2.png

    Checkbox Property Control Example

    This example demonstrate how to create a checkbox to turn on and off a visualization grid

    1. Create a Boolean Document Property called "cb"

    2. Create a script that triggers when Boolean Document Property changes

      from Spotfire.Dxp.Application.Visuals import Visualization
      myVis = myVis.As[Visualization]()
      myVis.XAxis.Scale.ShowGridlines = Document.Properties["cb"]
      myVis.YAxis.Scale.ShowGridlines = Document.Properties["cb"]
       
    3. Create a calculated value with custom expression and script

    custom expression: 

     if(${cb},"[X]",[ ])
     

    script

     Document.Properties["cb"] = not Document.Properties["cb"]
     

    Radio Button Property Control example

    In this example we create 3 radio buttons so the user can only select one option to set the label visibility mode

    1. Create a Boolean document property for each radio option. For example  "op1", "op2", "op3"

    2. Create a script that triggers when any of the Boolean document property changes

      if Document.Properties["op1"]: myVis.LabelVisibility = LabelVisibility.All
      if Document.Properties["op2"]: myVis.LabelVisibility = LabelVisibility.Marked 
      if Document.Properties["op3"]: myVis.LabelVisibility = LabelVisibility.None
       
    3. Create a calculated value with custom expression and script

    custom expression: 

     if(${cb},"(X)",( ))
     
    script
     
    Document.Properties["op1"] = False
    Document.Properties["op2"] = False
    Document.Properties["op3"] = False
    Document.Properties[dp] = True
     

    Video Tutorial

    Here is a video explaining what I mean in this article. Enjoy!

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...