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

How to prevent Run in Fit Model from producing a report?

I am writing a script that does the following:

 

  1. Opens a Fit Model window,
  2. Allows the user to populate it using the Macros and other functionality in the Fit Model window,
  3. Allows the user to click Run, at which point a possibly time-intensive calculation is performed and a report is produced.

 

The calculation that is performed when Run is clicked is produced by a script stored in the Run button.  This script produces a report, which is what the user should see.  However, because the script is added to the Run button, that desired report appears, but is then followed by the Fit Least Squares report that Run produces on its own.  The Fit Least Squares report is meaningless to the user. 

 

The script below illustrates the problem. In that script, the expression in the Run button, "runExpr", simply creates a clone data table; this is to simplify the illustration.  In the actual script, that expression (runExpr) performs a lot of analysis based on the effects entered in the Fit Model window. Also, in the actual script, the user populates the Fit Model window interactively; I populated the Fit Model window in the script below for convenience.

 

Names Default To Here( 1 );

runExpr = Expr(
// Creates a clone data table for illustration;
	dt << Subset( Output Table( "Clone Table" ), All rows );
);
	
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fmSLS = Fit Model(
	Y( :weight ),
	Effects( :age, :height, :age * :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" ),
);

r = fmSLS << Report;
r[Button Box( 9 )] << Set Script( runExpr);

When you click Run, as a user would, the clone table appears, but the window on top is the Fit Least Squares report produced by the Run command.  I would like to prevent that report from appearing. 

 

To that end:

 

  • I have tried using Throw() and Stop() in runExpr, but to no avail. 
  • I considered using a modal window, but I need the Macro functionality in the Fit Model window, and I can't see how to make a modal window help.
  • The only way I can think of even to address the Fit Least Squares report is to add a timing loop to the script as illustrated below. But this is fraught with peril.  There is no way to know how long it will take for the runExpr to complete, and if the user decides not to click Run, the script just keeps running until it times out.

 

Any thoughts or help would be greatly appreciated! 

 

Names Default To Here( 1 );

runExpr = Expr(
// Creates a clone data table for illustration;
	dt << Subset( Output Table( "Clone Table" ), All rows );
	fm_Flag = 1
);
	
fm_Flag = 0;  // Sets flag for timing
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fmSLS = Fit Model(
	Y( :weight ),
	Effects( :age, :height, :age * :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" ),
);
r = fmSLS << Report;

r[Button Box( 9 )] << Set Script( runExpr; fm_Flag = 1 );

For( i = 1, i <= 100, i++,
If(fm_Flag < 1, Wait(0.5), windowsopen = Get Window List(); windowsopen[nItems(windowsopen)] << Close Window; Stop() )
  );
1 ACCEPTED SOLUTION

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

Re: How to prevent Run in Fit Model from producing a report?

Ah ha!  Getting rid of or modifying the Run button seems difficult, but you can put your new button right on top of it (at least with JMP 15.2.1 on windows...):

 

Names Default to Here( 1 );

run expr = Expr(
	// desired report
	personality = Report( fm )[ComboBox(1)] << Get Selected;
	Show( personality );
);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

fm = dt << Fit Model(
	Y( :weight ),
	Effects( :age, :sex, :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" )
);

// New button the user should click on
(((fm << XPath("//ButtonBox[@title='Run']"))[1] << parent) ) << prepend(
	bb = Button Box("Launch custom script", run expr; fm << Close Window;) );

//make sure it is right on top of the old one
bb << set property("Margin", {Left(0), Right(0), Bottom(0), Top(0)});
	
// Rename old button in case it isn't hidden, and show error if user clicks it
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Script( New Window( "Use other button", 
	Text Box("Woops...\!n\!nPlease use the button at the bottom of the fit model dialog to launch this script.")));
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Button Name( "Do Not Use");

View solution in original post

10 REPLIES 10

Re: How to prevent Run in Fit Model from producing a report?

I don't see how to modify the script that you attach to the Run button box, but you can find and close the window afterward. See this illustration:

 

fm = Current data Table() << Fit Model(
	Y( :weight ),
	Effects( :age, :sex, :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Effect Leverage" )
);

fls = fm << Run;

window = Get Window List();

For( w = 1, w <= N Items( window ), w++,
	If( Contains( window[w] << Get Window Title, "Fit Least Squares" ),
		window[w] << Close Window;
		Break();
	);
);

 

 

marie_gaudard
Level III

Re: How to prevent Run in Fit Model from producing a report?

Mark, thank you, but I don't think that this works for my situation.  The user needs to populate the Fit Model window.  If I add your window component to my script, it runs before the user has populated the Fit Model window.  So, when the user clicks Run, that part of the script is "gone".  Please see the second script in my post to see my very inelegant workaround along the lines that you are proposing.  One has to account for the time that the user takes to populate Fit Model, and then the time it takes to run the script in the Run button.

Re: How to prevent Run in Fit Model from producing a report?

You are correct. I tried to modify my illustration but the script that is attached to the button box is evaluated before the Fit Least Squares report is created, so it is ineffective.

 

Names Default to Here( 1 );

run expr = Expr(
	// desired report
	personality = Report( fm )[ComboBox(1)] << Get Selected;
	Show( personality );
	// undesired report
	window = Get Window List();
	For( w = 1, w <= N Items( window ), w++,
		If( Contains( window[w] << Get Window Title, "Fit Least Squares" ),
			window[w] << Close Window;
			Break();
		);
	);
);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

fm = dt << Fit Model(
	Y( :weight ),
	Effects( :age, :sex, :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" )
);
Report( fm )[ButtonBox(9)] << Set Script( run expr );

// nothing after this point
marie_gaudard
Level III

Re: How to prevent Run in Fit Model from producing a report?

Right, it seems that the script in the button box gets run before the built-in behavior of the Run button is executed.
This little issue is vexing! There has to be a way to hold off on execution of the script until an action (like pressing the Run button) occurs. Or, to prevent the execution of the built-in behavior (but as I said, placing Throw and Stop in runExpr didn't work).
Thanks for trying to help, Mark.
ih
Super User (Alumni) ih
Super User (Alumni)

Re: How to prevent Run in Fit Model from producing a report?

How much of the Model Specification dialog box do you need? I can't help but think you would be better served replacing that step with a new window catered to your exact needs.  Examples in this post might help:

Prompting for columns, totally modally 

 

If you want to use the Model Specification window, you could give the user a new button to click on:

 

Names Default to Here( 1 );

run expr = Expr(
	// desired report
	personality = Report( fm )[ComboBox(1)] << Get Selected;
	Show( personality );
);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

fm = dt << Fit Model(
	Y( :weight ),
	Effects( :age, :sex, :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" )
);


// Show error if user clicks the wrong button
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Script( New Window( "Use other bottom", 
	Text Box("Woops...\!n\!nPlease use the button at the bottom of the fit model dialog to launch this script.")));

// Button the user should click on
(fm << XPath("//OutlineBox"))[1] << Append(Button Box("Launch custom script", run expr; fm << Close Window;));

 

 

 

marie_gaudard
Level III

Re: How to prevent Run in Fit Model from producing a report?

Thanks so much for this suggestion - it's not something that I had considered, and it may be the best one can do.  If the user clicks "Run", though, which is bound to happen, then Fit Model gets run, and the user has to run the script again.  It's not optimal.  But maybe I can leverage this idea.

 

Both you and Mark have raised a good question, namely, why do I insist on using the Fit Model window.  It is because I need to allow the user to access the Macros and Cross functionality.  Users will be adding effects that they consider important, and in many cases, these would include a full factorial model along with some additional three-way interaction terms.  I toyed with the idea of creating a modal dialog that would allow users to enter "types" of models, but this functionality would limit the user.  So I kept coming back to the need to have a window with most of the functionality of Fit Model.  Also, users are familiar with entering effects using Fit Model, so using that dialog makes sense from that perspective.  (I appreciate the link that you provided, ih, but it does not address the construction of effects.  It would take a lot of scripting to replicate the Cross, Full Factorial, Factorial to Degree, and Polynomial to Degree functionality that exists in Fit Model.  In fact, I don't think that I am capable!)

 

Now, why don't I want to run Fit Model?  This is because all I need are the responses and the effects; I simply need Fit Model's functionality to construct effects.  The custom script uses these, together with the fractional randomly-weighted bootstrap, to create models using model averaging.  The script to create these models and a summary report, is currently the expression that is placed in the Run button.  So clicking Run creates that custom report.  All is good, except that the report produced by Fit Model, which is irrelevant, appears over the custom report when the user clicks Run.

 

Again, thank you for your help.  I'll definitely play with the custom button idea. 

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

Re: How to prevent Run in Fit Model from producing a report?

Ah ha!  Getting rid of or modifying the Run button seems difficult, but you can put your new button right on top of it (at least with JMP 15.2.1 on windows...):

 

Names Default to Here( 1 );

run expr = Expr(
	// desired report
	personality = Report( fm )[ComboBox(1)] << Get Selected;
	Show( personality );
);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

fm = dt << Fit Model(
	Y( :weight ),
	Effects( :age, :sex, :height ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" )
);

// New button the user should click on
(((fm << XPath("//ButtonBox[@title='Run']"))[1] << parent) ) << prepend(
	bb = Button Box("Launch custom script", run expr; fm << Close Window;) );

//make sure it is right on top of the old one
bb << set property("Margin", {Left(0), Right(0), Bottom(0), Top(0)});
	
// Rename old button in case it isn't hidden, and show error if user clicks it
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Script( New Window( "Use other button", 
	Text Box("Woops...\!n\!nPlease use the button at the bottom of the fit model dialog to launch this script.")));
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Button Name( "Do Not Use");
marie_gaudard
Level III

Re: How to prevent Run in Fit Model from producing a report?

Oh my goodness, that is brilliant!!!  What a perfect "out-of-the-box" solution!!! 

I was planning to play with the placement of the custom button later today, but I don't know that I would ever have tried to place it over the Run button.  This is a great solution, and I think I will be able to use this concept elsewhere as well.  I bet that many users will find it useful!

Thank you so much!!!

Re: How to prevent Run in Fit Model from producing a report?

Why are you using the Fit Model dialog if you do not want the Fit Least Squares platform? There might be another way to achieve what you want.