cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Generalizing an App Builder Parameterized Application
Parameterized applications work well when the number and types of columns don't change. Using App Builder with many of JMP's platforms requires there to be a one-to-one correspondence between number and types of columns used to initially build the report and the columns used for future analysis. In many cases, this is too restrictive.

 

To circumvent this problem, it is possible to generalize applications so that any number or types of columns can be used, where applicable. The biggest drawback is that the built in dialog box for user input is no longer available. Fortunately, App Builder makes it easy to create and use a dialog box to launch a report window.


Ingredients:
  • Application Builder
  • Expression Handling

Sample Data Tables – Cars 1993, Cities

Difficulty – Hard
Video Length – 8:04

Steps

 

  1. Open the application created in the Building a Parameterized Application recipe. The Cars 1993 sample data table will open with it because it was used to create the recipe.
  2. Since we won’t be using a parameterized approach, we’ll have to build our own dialog for user input. Start by adding a new Module.
  3. In the Properties panel rename Module to Dialog.
  4. Change the report type to Dialog. This suppresses the menu at the top of the dialog window.
  5. Under the Input outline in the Sources panel drag a Filter Col Selector into the workspace. Change Variable Name to clbAll.
  6. Add a Line up Box.
  7. Drag two Col List Boxes and two Button Boxes into the Lineup and arrange them two by two with each row getting a button followed by a Col List Box. The blue outline inside the Lineup shows where the object will be located. You can also put an object in a drop area if it exists. A data table must be open in the current application for the Filter Col Selector and Col List boxes to be available.Screenshot 2023-11-27 at 3.45.52 PM.png
  8. Change the first button Variable Name property to btnY and the Title to Add Y.
  9. Change the other button Name and Title property to btnX and Add X, respectively.
  10. Set the Variable Name for the first list box to clbY.
  11. Uncheck all items but Continuous for Modeling Type so that only continuous columns can be added.  
  12. Change Min Items to 1. The hint inside the box changes from optional to required.
  13. Set Max Items to 1, limiting the number of items that can be put inside the box.
  14. Finally, change N Lines to 2. This will change the height of the box.
  15. Set the Variable Name of the second col list to clbX and change N Lines to 8.
  16. Add a V List Box around the Lineup.
  17. Drag a new Button Box inside the V List so it appears at the bottom. Change the Name of the new button to btnRemove and the Title to Remove Selected.
  18. Add an H Center Box around the button.
  19. Select the Filter Col Selector and V List Box surrounding the other elements. Right click and add an H List Box. Right click the outermost box and select Move to Corner.
  20. Add two buttons with titles Run and Cancel renaming their variables btnRun and btnCancel, respectively.
  21. Position them in an H List Box, then an H Center Box.
  22. Select the H Center Box and H List Box containing the other objects and add them to a V List Box.Screenshot 2023-11-27 at 3.56.54 PM.png

    Now that we have the dialog built, let’s add functionality to the buttons.

  23. Select the Cancel button. Scroll to the bottom of the Properties panel. The last property, Press, is associated with the button script. A script can be added directly to the entry box on the right or, if more space is needed, clicking the three-dot button opens a window with more space. This is one of two places where object scripts can be located.
  24. Use the following code for the button:
    (thisModuleInstance << Get Box) << Close Window;

    The thisModuleInstance namespace reference is needed to get the Cancel button to work. Each module creates its own namespace reference with the same name. Because their scope does not extend outside of the module to which they are associated, they can all have the same name. This is important to recognize when working with multiple modules. The Get Box message is used to get a reference to the dialog window and Close Window to close it.

  25. Select the Add Y button. Right click and select Scripts > Press at the bottom. This creates a default name for the script, adds it to the Run button’s Press property and adds a script shell in the Scripts tab, the second place a script can be located. The script name in the Properties panel must be the same as the script name in the Scripts tab for it to work correctly.
  26. Repeat this for the Add X and Remove Selected buttons.
  27. Go to the Scripts tab. Delete the default comments and code that has been added to the scripts. The argument thisBox is a reference to the object for which the script is associated. All App Builder script properties use thisBox as their first argument. It is optional and can be removed if it is not used and there are no other arguments needed.
  28. For the Add Y button script, add the following line:
    clbY << Append(clbAll << Get Selected)

    This will cause what is selected in the Filter Col Selector to be added to the Y list box.

  29. Add the same script for the Add X button replacing clbY with clbX.
  30. Use the following two lines for the Remove Selected button:
         clbY << Remove Selected;
         clbX << Remove Selected;
  31. Add a script for the Run button. Use the following code:
    If(N Items(clbY << Get Items) > 0 & N Items(clbX << Get Items) > 0,
    	(thisModuleInstance << Get Box) << Close Window;
    	thisApplication:Report << Create Instance(clbY << Get Items,clbX << Get Items);
    )

    The If statement checks that there is at least one item in both the X and Y col list boxes. If this condition is met, line 2 closes the dialog window, and line 3 launches the report module. thisApplication is the namespace used by the application that scopes to all objects and variables created in it. In this case, it is used to reference the report module and it’s optional. Create Instance is the message used to launch a module. Its arguments get passed to the OnModuleLoad function of the launched module. We will pass the contents of the List Box in which the user selects the analysis columns.

  32. Select the Module and rename it to Report. Uncheck Auto Launch at the lower right to keep it from launching when the application starts.
  33. Delete the three reports that are currently in the report. We will JSL to build them at runtime, after the user has selected the analysis columns.
  34. Rename the Tab Page Boxes tpbDistribution, tpbFitYbyX, and tpbScatter.
  35. To finish building the application, navigate to the Report section of the Scripts tab. It can be found by selecting the Scripts tab and choosing Report using the combo box at the top. We used Create Instance in the Dialog module script to launch the report and pass it the analysis columns. A module receives any arguments in its OnModuleLoad function. This happens before any of the report visuals are rendered. The following code will receive the passed variables and assign them variables local to the module (i.e., in the thisModuleInstance namespace for report).
    OnModuleLoad({yCols,xCols},
         allCols = Insert(yCols,xCols);
         yVars = yCols;
         xVars = xCols;
    );

    The variable allCols combines the X and Y variables for the Scatterplot platform.

  36. The Append function will be used to add the platforms to the appropriate Tab Page Boxes.
    tpbDistribution << Append();
    tpbFitYbyX << Append( );
    tpbScatter << Append()
  37. Working from the saved scripts from the Parameterized Application recipe, copy and paste the Scatterplot Matrix code into the Append function for tpbScatter. Delete the list of hard coded column names and replace them with Eval(allCols).
    tpbScatter << Append(	
    	Scatterplot Matrix(
    		Y( Eval(allCols) ),
    	)
    )
  38. We will use an alternative form for the Distribution platform:
    tpbDistribution << Append(	
    	Distribution(
    		Y(Eval(allCols))
    	)
    );

    The advantage of this approach is that the modeling types for the input columns need not be specified, making the code much simpler.

  39. We will also use an alternative for Fit Y by X
    tpbFitYbyX << Append(	
    	Fit Y by X(
    		Y( Eval(yVars)),
    		X( Eval(xVars) )
    	) << Fit Line << ANOVA;
    );

    In addition to not having to change the platform call for the different modeling types, the Fit Line and ANOVA messages can both be used making the code more compact.

You can test the application with the Cities sample data table. While you are limited to a single response column, the number and modeling types for the X columns are not restricted.