cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
CoxOcelot805
Level I

JSL scripting to create subset data tables in application builder

I am trying to develop a JMP add-in for the first time using the application builder, but got stuck with the JSL scripting as described below:

 

Some Background:

The interface was built under the Dialog tab.
There are three panel boxes with the titles of Columns, Roles and Action, and variable names of ColumnsPanel, RolesPanel and ActionPanel, respectively.

 

Under Columns panel, I added a Col List Box (All) with the variable name of ColList where it pulls into all the columns in the opened data table.

 

Under Roles panel, I added three Col List Boxes and three Button Boxes:
the variable names for the first, second and third Col List Box are ResponseColList, FactorColList and BlockColList, respectively.
the variable names for the first, second and third Button Box are ResponseButton, FactorButton and BlockButton, respectively.
the titles for the first, second and third Button Box are Response, Factor and Block, respectively.

 

Under the Action panel, I added three Button Boxes with the titles of OK, Remove and Cancel, and variable names of OKButton, RemoveButton and CancelButton, respectively.
When I click the Response Button, it added the columns of attribute "A", "B", "C", "D" and "E" from ColList.
Similarily, when I click the Factor and Block Button, it added the column of "Site" and "People" from ColList.

 

Capture.PNG

 

Scripts:

 

//Part I
//Places selected columns into Role panel
On Response = Function({},
		ResponseColList << Append( AllColList << Get Selected)
);

//Places selected columns into Factor panel
On Factor = Function({},
		FactorColList << Append( AllColList << Get Selected)
);

//Places selected columns into Block panel
On Block = Function({},
		BlockColList << Append( AllColList << Get Selected)
);

// Program the OK Button
On OK = Function({},
Response = ResponseColList << Get Items;
Factor = FactorColList << Get Items;
Block = BlockColList << Get Items;

// Get the current data table
    dt = Current Data Table();
    
// Perform principal component analysis
    pca = dt << Principal Components(
    Y( Eval List( Response ) ),
    Estimation Method( "NIPALS" ),
    Standardize( "Standardized" )
);

pca << Save Principal Component Values( 3 );
pca << Close Window();

// Create a subset and delete columns "Prin1", "Prin2" and ""Prin3" in "dt"
dt << Subset(
        Output Table("MET"),
        All rows,
        columns(Eval List(Block), Eval List(Factor), :Prin1, :Prin2, :Prin3)
    );
    
    dt << Delete Columns( "Prin1" ) << Delete Columns( "Prin2" ) << Delete Columns( "Prin3" );
    
// Standardize column attributes and create a data table "MET"
Current Data Table(Data Table("MET"));
    For Each({col, index}, {:Prin1, :Prin2, :Prin3},
        col << Format("Fixed Dec", 12, 2)
    );

MET = Data Table( "MET" );


//Part II
//Get the levels in the Factor column
factorLevels = Associative Array(MET, Column(Eval List(Factor))) << Get Keys;
level1 = factorlevels[1];
level2 = factorlevels[2];

// Create two subsets named "Group1" and "Group2"
MET << Select Where( Column(Eval List(Factor)) == level1 ) << Subset( Output Table( "Group1" ), Selected Rows( 1 ), Selected columns only( 0 ) );
MET << Select Where( Column(Eval List(Factor)) == level2 ) << Subset( Output Table( "Group2" ), Selected Rows( 1 ), Selected columns only( 0 ) );
Group1 = Data Table( "Group1" );
Group2 = Data Table( "Group2" );

// Access the Site levels in "Group1" and "Group2"
Site_level1 = Column( Group1, "Site" ) << Get Values;
Site_level2 = Column( Group2 "Site" ) << Get Values;

);

I can successfully run the Part I scripts but keep getting errors in Part II, so really appreciate some help debugging the code.

 

Another goal here is to handle datasets with different attribute names (e.g., attribute "F", "G", etc.), I would like to ensure that the script uses the selected column names dynamically rather than hardcoding specific names.

 

Thank you!

2 REPLIES 2
jthi
Super User

Re: JSL scripting to create subset data tables in application builder

Which parts of Part2 are failing and errors are you getting?

-Jarmo
hogi
Level XI

Re: JSL scripting to create subset data tables in application builder

The associative array - with a data table as first argument?

Names Default to Here(1);
MET = Open( "$SAMPLE_DATA/Big Class.jmp" );

Factor={"height", "weight"};
Associative Array(MET, Column(Eval List(Factor)))

hogi_0-1719319909046.png