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.
Pass a List of column names via Document/Datatable poperty to S+ - TIBCO Spotfire Community

Pass a List of column names via Document/Datatable poperty to S+

Last post Wed, Aug 8 2012 9:49 AM by Dan White. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • Tue, Jun 22 2010 12:35 PM

    • shilpi
    • Not Ranked
    • Joined on Tue, Jun 22 2010
    • Posts 3

    Pass a List of column names via Document/Datatable poperty to S+

    Hi,

    I have an Splus script that requires a list of column names (e.g c("Col1","Col2","Col3","Col4") )as an input .It uses this list to subset a dataframe. These column names are to be selected by the user using a multiselect list box which is populated with the column names of a datatable.

    What would be the best way to do this??Please advice.

  • Wed, Jun 23 2010 12:33 AM In reply to

    Re: Pass a List of column names via Document/Datatable poperty to S+

    There are likely several ways to do this, but here's one:

    1. Register a new data function
      1. Go to Tools|Register Data Function...
      2. Select "S-PLUS Script" for the Type
      3. Give the data function a name, e.g. "Subset by Column Names"
      4. Paste in the following script:

        library(bigdata)


        column.names.list = strsplit(column.names[1],"[ ]?,[ ]?")
        output.data <- bd.filter.columns(data=input.data,keep=unlist(column.names.list))

      5. Create the first required input parameter "input.data" as a Table
      6. Create the second required input parameter "column.names" as a Value
      7. Create the output parameter "output.data" as a Table
      8. Save the Data Function to the Library.
    2. Add a text area with list box for column selection
      1. <Ctrl-t> to add a new Text Area
      2. Add a multi-select List box to the text area
      3. Create a new document property (e.g., name="selectedColumns", type="String") to store the values in the list box
      4. Set property value through "Column selection"
      5. Choose your source data table from which the column names should populate the list box
      6. Click
    3. Map the Data Function to the document property (this is the most important part)
      1. Go to Tools|Data Functions...
      2. Select the data function "Subset by Column Names"
      3. Assign the input property "input.data" to your source data table
      4. Assign the input parameter "column.names" to the Expression: "$map("${selectedColumns}", ",")", where "selectedColumns" is the name of the document property storing the list of selected column names
      5. Assign the output parameter "output.data" to return a new data table
    4. You may now select multiple columns in the List box, the data will be sent to S-PLUS, and the subset of data will be returned as a new data table.

    In practicality, there are a couple of things to consider:

    1. Assuming the data to subset are already in Spotfire, you should subset the data locally (in Spotfire) before passing it to S+ or R.
    2. If the data do not already exist in Spotfire, you can create one data function that loads the data remotely in S+ and returns only the column names to Spotfire, and then modify the above S+ script and function registration to eliminate the "input.data" parameter.

    I hope this helps.

    (If I can figure out how to post screenshots, I'll add another post with more details.)

  • Wed, Aug 8 2012 4:48 AM In reply to

    Re: Pass a List of column names via Document/Datatable poperty to S+

    Hi Dan

    I have a similar query with respect to passing values taken from drop down to a SAS script.

    For example

    I have a data set with say columns X & Y. As part of UI we are creating drop downs so that user can choose values from drop downs X & Y. Once this is done I need to pass values to a SAS script that will calculate the values and send it back.

    Could you guide me withh this please

  • Wed, Aug 8 2012 9:49 AM In reply to

    Re: Pass a List of column names via Document/Datatable poperty to S+

    Hi sharath.nair,

    For SAS, it's exactly the same process, with two exceptions:

    1. Choose "SAS Script" when you create the Data Function.
    2. Scalar values are passed in to SAS as macro variables.

    You only need the "$map" step if you're permitting multiple selection in the input control; otherwise, you just assign your input control's document property directly to your SAS input variable.

    Write back if you get stuck.

    -Dan

Page 1 of 1 (4 items)
┬ęCopyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center