cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
paul_vanoppen
Level III

How do I create a modal selection window with multiple selection

Hello JMP community,

I need some help with the following: I have a table (dt) with a nominal numeric column (Values). I would like to create a window that displays the sorted unique values of the Values column. Then I would like to select one or multiple values return those and pass them to a Select Where function.

I am absolutely a beginner at JSL and your help is appreciated.

 

To solve this issue, I created a function SelectNumericValues as follows:

// function to create a modal window with selection functionality
SelectNumericValues = Function( {dt, column_name}, // Use Summarize to find unique values in the specified column Summarize( unique_values = By( Column( dt, column_name ) ) ); // Calculate the maximum number of selections max_selections = N Items( unique_values ); // Create a window for user selection nw = New Window( "Select Values", <<Modal, <<Return Result, V List Box( Text Box( "Select values for analysis:" ), lb = List Box( unique_values, Max Selected( max_selections ) ), H List Box( Button Box( "OK", selected_values = lb << Get Selected; //nw << Close Window; ), Button Box( "Cancel", selected_values = {}; nw << Close Window; ) ) ) ); // Wait for user input selected_values = nw << Show Window; // Return the selected values selected_values; );

// call my function with table dt and nominal numeric column "Values"
selected_values = SelectNumericValues(dt, "Values");

dt_select = dt << Select Where( :Values == selected_values)

The window with the unique sorted values is correctly rendered:

paul_vanoppen_0-1727737764372.png

 

And I can select one or multiple options. But I end up with these two errors:

  • Send Expects Scriptable Object in access or evaluation of 'List' , {/*###*/"0", "1", "2"}
  • Name Unresolved: Button in access or evaluation of 'Button' , Button( 1 ) /*###*/

Which suggest that I am not handling the buttons correctly in the SelectNumericValues function and that I am also incorrectly dealing with the returned values in the Select Where function. 

 

paul_vanoppen_1-1727737820740.png

 

As an additional question: how would I implement the requirement that at least one option should be selected (closing the modal window with none selected should either not be possible, or it would implicitly mean that all options are selected). 

Thanks!


Paul

1 ACCEPTED SOLUTION

Accepted Solutions
paul_vanoppen
Level III

Re: How do I create a modal selection window with multiple selection

I found a working solution. I made the following mistakes:

  • the function SelectNumericValues returns a list of characters, not of numbers.
  • the Select Where function call requires the function Contains to match the list of numbers.
  • This line selected_values = nw << Show Window; in the SelectNumericValues function causes the button related error (I think)

As a result, I need to coerce the selected values to numeric. And I need to adjust the Select Where function call.

I find that this works correctly:


// Function to generate the user selection window for numeric values
SelectNumericValues = Function( {dt, column_name}, 
   // Use Summarize to find unique values in the specified column
	Summarize( unique_values = By( Column( dt, column_name ) ) );
    // Calculate the maximum number of selections
	max_selections = N Items( unique_values );

    // Create a window for user selection
	nw = New Window( "Select Values",
		<<Modal,
		<<Return Result,
		V List Box(
			Text Box( "Select values for analysis:" ),
			lb = List Box( unique_values, Max Selected( max_selections ) ),
			H List Box(
				Button Box( "OK",
					selected_values = lb << Get Selected;
					// Convert selected values to numeric
					For( i = 1, i <= N Items( selected_values ), i += 1,
						selected_values[i] = Num( selected_values[i] )
					);
				),
				Button Box( "Cancel",
					selected_values = {};
					nw << Close Window;
				)
			)
		)
	);

	// Return the selected values
	selected_values;
);

selected_values = SelectNumericValues(dt, "Values");
dt << Select Where( Contains( selected_values, :Values) );

I am happy to see additional improvements from other users.

View solution in original post

3 REPLIES 3
paul_vanoppen
Level III

Re: How do I create a modal selection window with multiple selection

I found a working solution. I made the following mistakes:

  • the function SelectNumericValues returns a list of characters, not of numbers.
  • the Select Where function call requires the function Contains to match the list of numbers.
  • This line selected_values = nw << Show Window; in the SelectNumericValues function causes the button related error (I think)

As a result, I need to coerce the selected values to numeric. And I need to adjust the Select Where function call.

I find that this works correctly:


// Function to generate the user selection window for numeric values
SelectNumericValues = Function( {dt, column_name}, 
   // Use Summarize to find unique values in the specified column
	Summarize( unique_values = By( Column( dt, column_name ) ) );
    // Calculate the maximum number of selections
	max_selections = N Items( unique_values );

    // Create a window for user selection
	nw = New Window( "Select Values",
		<<Modal,
		<<Return Result,
		V List Box(
			Text Box( "Select values for analysis:" ),
			lb = List Box( unique_values, Max Selected( max_selections ) ),
			H List Box(
				Button Box( "OK",
					selected_values = lb << Get Selected;
					// Convert selected values to numeric
					For( i = 1, i <= N Items( selected_values ), i += 1,
						selected_values[i] = Num( selected_values[i] )
					);
				),
				Button Box( "Cancel",
					selected_values = {};
					nw << Close Window;
				)
			)
		)
	);

	// Return the selected values
	selected_values;
);

selected_values = SelectNumericValues(dt, "Values");
dt << Select Where( Contains( selected_values, :Values) );

I am happy to see additional improvements from other users.

txnelson
Super User

Re: How do I create a modal selection window with multiple selection

I think you need to look into using a Data Filter.  It will do the display and the selection for you.

Jim
paul_vanoppen
Level III

Re: How do I create a modal selection window with multiple selection

Thanks Jim!

Based on your recommendation I created a script using the Data Filter function. Thanks for pointing me to it as it is a very useful function for interactive filtering of data.

The main functionality that my script is implementing is to create output (a journal, saved e.g. as a pdf document) based on the data after it is filtered by the user. In other words, there is no need here for any interactive, multi-variate, filtering. In that sense, the approach I have shared in this post is useful to me.

 

Paul