cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
SDF1
Super User

JSL Help with: Get As Report & Table Box

Hi All,

 

  I've recently started writing JSL that summarizes some information in a new window using the Table Box() functionality because I want users to be able to select rows to perform the next step a process. Sometimes making an interactive table box can be cumbersome. I've also recently learned that you can take a data table and turn it into an interactive table box-like interface using the Get As Report command, which makes building the interface much easier and faster.

 

See for example this JSL:

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );

RptWin = New Window( "Data Table as report",
Outline Box("Data Table as Report",
	dt_Rpt = dt << Get as Report(); 
		
	)
);

 

 

  The only problem I'm having is how to use the output in the new window like I can with a Table Box.

 

  In the Table Box environment, you can set functions so that it returns the information within that you select and that can be used further down the code. However, the Get As Report command doesn't let you do that. At least I haven't found any examples of how to do it, and the Scripting Index doesn't have much on the Get As Report command.

 

The following code is an example of how I've built a table box that has a single row selectable at a time.

tb = Table Box(
	Number Col Box( "PC Number", Eval List( PC_n ) ),
	Number Col Box( "Eigenvalue", Eval List( PC_eigv ), <<Set Format( "Fixed Dec", 6, 6 ) ),
	Number Col Box( "Percent", Eval List( PC_per ), <<Set Format( "Fixed Dec", 6, 6 ) ),
	Plot Col Box( "",
		Eval List( PC_per ),
		<<Set Scale( 0, 100, "Percent" ),
		<<Lower( PC_cump ),
		<<Upper( PC_cump )
	),
	Number Col Box( "cumulative Percent", Eval List( PC_cump ), <<Set Format( "Fixed Dec", 6, 6 ) ),
	<<Set Shade Headings( 1 ),
	<<Set Heading Column Borders( 1 ),
	<<Set Selectable Rows( 1 ),
	<<Set Row Change Function(
		Function( {this},
			{SelRows},
			SelRows = this << Get Selected Rows;
			If(
				N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
				N Items( SelRows ) == 1,
					SelRows = this << Get Selected Rows;
					N_PCs = SelRows[1];
			);
		)
	)
)

 Is there a way to get have the same kind of functionality when using the Get As Report output?

 

Thanks for any feedback!,

DS

2 ACCEPTED SOLUTIONS

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: JSL Help with: Get As Report & Table Box

I think so, you just need to go one level lower in the reference reference returned from the Get are Report() function to get to the table.  Try this:

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );

RptWin = New Window( "Data Table as report",
	Outline Box("Data Table as Report",
		dt_Rpt = dt << Get as Report(); 
	)
);

tb = dt_Rpt[Table Box( 1 )];

tb << Set Shade Headings( 1 );

tb << Append(
	Plot Col Box( "",
		:mvalue << get values,
		<<Set Scale( 0, 100, "Percent" ),
		<<Lower( :mvalue ),
		<<Upper( :mvalue )
	)
);
	
tb << Set Heading Column Borders( 1 );
tb << Set Selectable Rows( 1 );
tb << Set Row Change Function(
	Function( {this},
		{SelRows},
		SelRows = this << Get Selected Rows;
		If(
			N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
			N Items( SelRows ) == 1,
				SelRows = this << Get Selected Rows;
				N_PCs = SelRows[1];
		);
	)
);

View solution in original post

ih
Super User (Alumni) ih
Super User (Alumni)

Re: JSL Help with: Get As Report & Table Box

You bet. The graph is already tied to the table, so I think if you just add the two rows below to your Set Row Change Function you should see that behavior.

 

	tb << Set Row Change Function(
		Function( {this},
			{SelRows},
			SelRows = this << Get Selected Rows;
			If(
				N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
				N Items( SelRows ) == 1,
					SelRows = this << Get Selected Rows;
					NPCs = SelRows[1];
			);
			// ** Added next two lines **
			dt_results << Clear Select;
			dt_results << Select rows(SelRows);
		)
	);

View solution in original post

4 REPLIES 4
ih
Super User (Alumni) ih
Super User (Alumni)

Re: JSL Help with: Get As Report & Table Box

I think so, you just need to go one level lower in the reference reference returned from the Get are Report() function to get to the table.  Try this:

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );

RptWin = New Window( "Data Table as report",
	Outline Box("Data Table as Report",
		dt_Rpt = dt << Get as Report(); 
	)
);

tb = dt_Rpt[Table Box( 1 )];

tb << Set Shade Headings( 1 );

tb << Append(
	Plot Col Box( "",
		:mvalue << get values,
		<<Set Scale( 0, 100, "Percent" ),
		<<Lower( :mvalue ),
		<<Upper( :mvalue )
	)
);
	
tb << Set Heading Column Borders( 1 );
tb << Set Selectable Rows( 1 );
tb << Set Row Change Function(
	Function( {this},
		{SelRows},
		SelRows = this << Get Selected Rows;
		If(
			N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
			N Items( SelRows ) == 1,
				SelRows = this << Get Selected Rows;
				N_PCs = SelRows[1];
		);
	)
);
SDF1
Super User

Re: JSL Help with: Get As Report & Table Box

Hi @ih ,

 

  Thanks for the quick reply and solution -- that is exactly what I'm looking for. Works perfectly. Here's the larger bit of code where I was trying to implement it. I know this is a separate topic, but do you by chance happen to know how I can link the graph builder display in the code below with the Get As Report table box so that when the user clicks on the row in the table box it highlights the corresponding data point in the graph builder?  By the way, I am just using the Boston Housing as a sample data set with mvalue as the response and all other columns as predictors in the partition -- and I'm using a validation portion of 0.3.

 

Thanks!,

DS

Names Default To Here( 1 );

lbWidth = 168;

dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );

// Expression to store the current settings in global variables
recallRolesS1 = Expr(
	::dtchosenRecall = dtchosen
);

// Expression to clear all current settings. KW: Clear
clearRoles = Expr(
	Try(
		colListY << RemoveAll;
		ColListX << RemoveAll;
		ColListW << RemoveAll;
		ColListF << RemoveAll;
		colListV << RemoveAll;
	)
);

// Expression to store the current settings in global variables
recallRoles = Expr(
	::ycolRecall = colListY << GetItems;
	::xcolRecall = colListX << GetItems;
	::WcolRecall = colListW << GetItems;
	::FcolRecall = colListF << GetItems;
	::vcolRecall = colListV << GetItems;
	::max_spRecall = max_sp_input << get;
	::partVPRecall = partVP_input << Get;
);

//Function to choose the data table to model. KW: choose_data
choose_data_table = Function( {},
	list = {};
	For( i = 1, i <= N Table(), i++,
		list[i] = Data Table( i ) << get name
	);
	win = New Window( "Select a data table",
		<<Modal,
		hb = H List Box(
			Panel Box( "Choose a data table", dt = List Box( list, max selected( 1 ), dtchosen = Data Table( (dt << get selected)[1] ) ) ), 

		)
	);
);

Part_rerun = Expr(
	
	Close( dt_results, No Save );
	
	NPCs_num = NPCs;
	
	str = Eval Insert(
		"report = (dtchosen<<Partition(
				Y(Eval(ycols)),
				X(Eval(xcols)),
				Weight(Eval(wcols)),
				Freq(Eval(Fcols)),
				Validation(Eval(vcols)),
				Informative Missing(1),
				Split Best(^NPCs_num^),
				Validation Portion(^partVP^),
				Split History(1)
				)
				
			)<<Report;"
	);
	Eval( Parse( str ) );
	
);

Part_TB = Expr(

	Part_TBWin = New Window( "Select the Best split to re-run",
		<<Return Result,
		<<On Validate,
		Outline Box( "Partitioning Results (Select the best to re-run))",
			H List Box(
				If(
					N Items( vcols ) == 1 | (N Items( vcols ) == 0 & Is Missing( PartVP ) == 0),
						part_gb = Graph Builder(
							Size( 579, 417 ),
							Show Control Panel( 0 ),
							Variables(
								X( :Splits ),
								Y( :Training RSquare ),
								Y( :Validation RSquare, Position( 1 ) ),
								Y( :RSquare Diff ),
								Y( :Penalized Valid RSquare, Position( 2 ) )
							),
							Elements( Position( 1, 1 ), Line( X, Y( 1 ), Y( 2 ), Legend( 12 ) ), Points( X, Y( 1 ), Y( 2 ), Legend( 14 ) ) ),
							Elements( Position( 1, 2 ), Line( X, Y( 1 ), Y( 2 ), Legend( 13 ) ), Points( X, Y( 1 ), Y( 2 ), Legend( 15 ) ) ),
							SendToReport(
								Dispatch(
									{},
									"graph title",
									TextEditBox,
									{Set Text( "Training & Validation RSquare / RSquare Diff & Penalized Valid RSquare vs. Splits" )}
								)
							)
						),
					N Items( vcols ) == 0 & Is Missing( PartVP ) == 1,
						part_gb = Graph Builder(
							Size( 531, 456 ),
							Show Control Panel( 0 ),
							Variables( X( :Splits ), Y( :Training RSquare ), Y( :Penalized Train RSquare ) ),
							Elements( Position( 1, 1 ), Line( X, Y, Legend( 7 ) ), Points( X, Y, Legend( 9 ) ) ),
							Elements( Position( 1, 2 ), Line( X, Y, Legend( 8 ) ), Points( X, Y, Legend( 11 ) ) )
						)
				),
				dt_tb = dt_results << Get As Report(),
				Panel Box( "Action",
					Lineup Box( N Col( 1 ),
						Text Box( "Re-run Partion", <<Justify Text( "Center" ) ),
						Button Box( "OK",
							//NPCs = dt_results << Get selected rows();
							Part_rerun;
							Part_TBWin << Close Window;
						),
						Button Box( "Cancel", Part_TBWin << Close Window ),
						Spacer Box( Size( 0, 8 ) ),
						Button Box( "Relaunch",
							Part_TBWin << Close Window;
							Firstwin;
						),
						Spacer Box( Size( 0, 8 ) ),
						Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
					)
				)
			)
		)
	);
	
	tb = dt_tb[Table Box( 1 )];
	tb << Set Shade Headings( 1 );
	tb << Set Heading Column Borders( 1 );
	tb << Set Selectable Rows( 1 );
	tb << Set Row Change Function(
		Function( {this},
			{SelRows},
			SelRows = this << Get Selected Rows;
			If(
				N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
				N Items( SelRows ) == 1,
					SelRows = this << Get Selected Rows;
					NPCs = SelRows[1];
			);
		)
	);
	
);


Part = Expr(
	If(
		N Items( vcols ) == 1,
			dt_results = New Table( "Partition_Results",
				Add Rows( max_sp ),
				New Column( "Splits", Numeric, Continuous ),
				New Column( "Training RSquare", Numeric, Continuous ),
				New Column( "Validation RSquare", Numeric, Continuous ),
				New Column( "Training RASE", Numeric, Continuous ),
				New Column( "Validation RASE", Numeric, Continuous ),
				New Column( "Training N", Numeric, Continuous ),
				New Column( "Validation N", Numeric, Continuous ),
				New Column( "RSquare Diff", Numeric, Continuous, Formula( "Training RSquare"n - "Validation RSquare"n ) ),
				New Column( "Penalized Valid RSquare", Numeric, Continuous, Formula( "Training RSquare"n - 0.05 * "Splits"n ) )
			),
		N Items( vcols ) == 0 & Is Missing( partVP ) == 0,
			dt_results = New Table( "Partition_Results",
				Add Rows( max_sp ),
				New Column( "Splits", Numeric, Continuous ),
				New Column( "Training RSquare", Numeric, Continuous ),
				New Column( "Validation RSquare", Numeric, Continuous ),
				New Column( "Training RASE", Numeric, Continuous ),
				New Column( "Validation RASE", Numeric, Continuous ),
				New Column( "Training N", Numeric, Continuous ),
				New Column( "Validation N", Numeric, Continuous ),
				New Column( "RSquare Diff", Numeric, Continuous, Formula( "Training RSquare"n - "Validation RSquare"n ) ),
				New Column( "Penalized Valid RSquare", Numeric, Continuous, Formula( "Validation RSquare"n - 0.05 * "Splits"n ) )
			),
		N Items( vcols ) == 0,
			dt_results = New Table( "Partition_Results",
				Add Rows( max_sp ),
				New Column( "Splits", Numeric, Continuous ),
				New Column( "Training RSquare", Numeric, Continuous ),
				New Column( "Training RASE", Numeric, Continuous ),
				New Column( "Training N", Numeric, Continuous ),
				New Column( "Penalized Train RSquare", Numeric, Continuous, Formula( "Training RSquare"n - 0.05 * "Splits"n ) )
			)
	);
	
	For( i = 1, i <= max_sp, i++,
		dt_results:"Splits"n[i] = i
	);
	
	dt_name = dtchosen << Get Name;
	
	For( i = 1, i <= N Rows( dt_results ), i++,
		Psplit = dt_results:"Splits"n[i];
		str = Eval Insert(
			"report = (dtchosen<<Partition(
				Y(Eval(ycols)),
				X(Eval(xcols)),
				Weight(Eval(wcols)),
				Freq(Eval(Fcols)),
				Validation(Eval(vcols)),
				Informative Missing(1),
				Split Best(^Psplit^),
				Validation Portion(^partVP^),
				Invisible
				)
				
			)<<Report;"
		);
		Eval( Parse( str ) );
		
		partWinName = Report << Get Window Title;
		
		w = Window( partWinName );
		RSq_mat = w[Outline Box( "Partition for " || ycols[1] )][Table Box( 1 )] << Get As matrix;
		
		If(
			N Items( vcols ) == 1,
				dt_results:"Training RSquare"n[i] = RSq_mat[1];
				dt_results:"Training RASE"n[i] = RSq_mat[2];
				dt_results:"Training N"n[i] = RSq_mat[3];
				dt_results:"Validation RSquare"n[i] = RSq_mat[2, 1];
				dt_results:"Validation RASE"n[i] = RSq_mat[2, 2];
				dt_results:"Validation N"n[i] = RSq_mat[2, 3];,
			N Items( vcols ) == 0 & Is Missing( PartVP ) == 0,
				dt_results:"Training RSquare"n[i] = RSq_mat[1];
				dt_results:"Training RASE"n[i] = RSq_mat[2];
				dt_results:"Training N"n[i] = RSq_mat[3];
				dt_results:"Validation RSquare"n[i] = RSq_mat[2, 1];
				dt_results:"Validation RASE"n[i] = RSq_mat[2, 2];
				dt_results:"Validation N"n[i] = RSq_mat[2, 3];,
			N Items( vcols ) == 0,
				dt_results:"Training RSquare"n[i] = RSq_mat[1];
				dt_results:"Training RASE"n[i] = RSq_mat[2];
				dt_results:"Training N"n[i] = RSq_mat[3];
		);
		Report << CloseWindow;
	);
	
	Part_TB;
);

AutoPart = Expr(
	Partwin = New Window( "",
		<<Return Result,
		<<On Validate,
		Border Box( Left( 3 ), Top( 2 ),
			Outline Box( "JSL to help with Partitioning",
				<<Set Font Size( 12 ),
				V List Box(
					H List Box(
						Panel Box( "Select Columns",
							V List Box( colListData = Col List Box( dtchosen, All, Grouped, width( lbWidth ), nLines( 12 ) ) ),
							Spacer Box( Size( 0, 16 ) )
						),
						Panel Box( "Cast Selected Columns into Roles",
							Lineup Box( N Col( 2 ), Spacing( 3, 2 ),
								Button Box( "Y, Response", colListY << Append( colListData << GetSelected ) ),
								colListY = Col List Box( width( lbWidth + 40 ), nLines( 4 ), Min Items( 1 ) ),
								Button Box( "X, Factor", colListX << Append( colListData << GetSelected ) ),
								colListX = Col List Box( width( lbWidth ), nLines( 4 ), Min Items( 1 ) ),
								Button Box( "Weight", colListW << Append( colListData << GetSelected ) ),
								colListW = Col List Box(
									width( lbWidth ),
									Max Selected( 1 ),
									Max Items( 1 ),
									nLines( 1 ),
									<<Set Data Type( "Numeric" )
								),
								Button Box( "Freq", colListF << Append( colListData << GetSelected ) ),
								colListF = Col List Box(
									width( lbWidth ),
									Max Selected( 1 ),
									Max Items( 1 ),
									nLines( 1 ),
									<<Set Data Type( "Numeric" )
								),
								Button Box( "Validation", colListV << Append( colListData << GetSelected ) ),
								colListV = Col List Box(
									width( lbWidth ),
									nLines( 1 ),
									Max Selected( 1 ),
									Max Items( 1 ),
									<<Set Data Type( "Numeric" ), 

								)
							)
						),
						Panel Box( "Action",
							Lineup Box( N Col( 1 ),
								Button Box( "OK",
									recallRoles;
									max_sp = max_sp_input << get;
									partVP = partVP_input << Get;
									ycols = ColListY << Get Items;
									xcols = ColListX << Get Items;
									Wcols = ColListX << Get Items;
									Fcols = ColListF << Get Items;
									vcols = ColListV << Get items;
									Part;
									Partwin << Close Window;
								),
								Button Box( "Cancel", Partwin << Close Window ),
								Spacer Box( Size( 0, 22 ) ),
								Button Box( "Remove",
									colListY << RemoveSelected;
									colListX << RemoveSelected;
									colListW << RemoveSelected;
									colListF << RemoveSelected;
									colListV << RemoveSelected;
								),
								Button Box( "Recall",
									clearRoles;
									Try(
										colListY << Append( ::ycolRecall );
										colListX << Append( ::xcolRecall );
										colListW << Append( ::WcolRecall );
										colListF << Append( ::FcolRecall );
										colListV << Append( ::vcolRecall );
										max_sp_input << Set( ::max_spRecall );
										partVP_input << Set( ::partVPRecall );
									);
								),
								Button Box( "Relaunch",
									FirstWin;
									Partwin << Close Window;
								),
								Spacer Box( Size( 0, 22 ) ),
								Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
							)
						)
					),
					H List Box(
						Panel Box( "Max partition splits", max_sp_input = Number Edit Box( 20, 6 ) ),
						Panel Box( "Validation Portion (if no validation column)", partVP_input = Number Edit Box( ., 6 ) )
					)
				)
			)
		)
	)
);

//Interactive dialogue window to start Generalized Tuning
FirstWin = Expr(
	AutoTuneDlg1 = New Window( "Partioning Automation",
		<<Return Result,
		<<On Validate,
		Border Box( Left( 3 ), top( 2 ),
			Outline Box( "Something to help simplify partitioning",
				<<Set Font Size( 12 ),
				H List Box(
					V List Box(
						Panel Box( "Select Data Table",
							H List Box( Button Box( "Select Data Table", choose_data_table ), Spacer Box( Size( 100, 0 ) ) )
						), 

					),
					Panel Box( "Action",
						Lineup Box( N Col( 1 ),
							Button Box( "OK",
								recallRolesS1;
								AutoPart;
								AutoTuneDlg1 << Close Window;
							),
							Button Box( "Cancel", AutoTuneDlg1 << Close Window ),
							Spacer Box( Size( 0, 25 ) ),
							Button Box( "Recall",
								Try(
									MMObj << Set( ::MMObjRecall );
									Try( dtchosen = ::dtchosenRecall );
								)
							),
							Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
						)
					)
				)
			)
		)
	)
);

FirstWin;
ih
Super User (Alumni) ih
Super User (Alumni)

Re: JSL Help with: Get As Report & Table Box

You bet. The graph is already tied to the table, so I think if you just add the two rows below to your Set Row Change Function you should see that behavior.

 

	tb << Set Row Change Function(
		Function( {this},
			{SelRows},
			SelRows = this << Get Selected Rows;
			If(
				N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
				N Items( SelRows ) == 1,
					SelRows = this << Get Selected Rows;
					NPCs = SelRows[1];
			);
			// ** Added next two lines **
			dt_results << Clear Select;
			dt_results << Select rows(SelRows);
		)
	);
SDF1
Super User

Re: JSL Help with: Get As Report & Table Box

Hi @ih ,

 

  Yes, perfect! That actually makes total sense, and I don't know why I didn't think of doing that.

 

Thanks again for the quick solution!,

DS