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=""> 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
N Items( SelRows ) == 1,
SelRows = this << Get Selected Rows;
N_PCs = SelRows[1];
);
)
)
)</SET> Is there a way to get have the same kind of functionality when using the Get As Report output?
Thanks for any feedback!,
DS
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
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);
)
);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> 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></PARTITION></MODAL>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=""> 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
N Items( SelRows ) == 1,
SelRows = this << Get Selected Rows;
N_PCs = SelRows[1];
);
)
);</SET>