Subscribe Bookmark RSS Feed

Linking a cell (in a JMP table) to a script?

olivia_manning

Community Trekker

Joined:

Jun 20, 2012

Hi,

I have a JMP script that produces a table (of analyzed data) with test names in the first column.

I was wondering if I could link each test name to a script that would then produce a series of graphs.

Does anyone know if that is at all possible?

Thanks,

Olivia

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The script below is for a table that has a formula column with a script to make graphs from rows.

When a row is selected, the contents of several of the columns for the selected row are made into a subset table, which is transposed so it can be graphed with an overlay plot. The original script that is in the formula column starts out looking a lot different, and its inclucded below the table script.

(copy the table script into a script window and run the script)

New Table( "result table",

Add Rows( 5 ),

New Column( "Analysis",

  Character,

  Nominal,

  Set Values( {"ANOVA", "Apple", "Bannana", "Orange", "Peach"} )

),

New Column( "Result 1",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 2",

  Numeric,

  Continuous,

  Format( "", 9 ),

  Formula( Random Uniform() )

),

New Column( "Result 3",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 4",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() ),

  Set Selected

),

New Column( "Result 5",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 6",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 7",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 8",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 9",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Column with Formula to make graphs",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula(

   If( Selected( Row State() ),

    Eval(

     Parse(

      Names Default To Here( 1 );

      Clear Symbols( 1 );

      dt0 = Current Data Table();

      rn = dt0 << get selected rows;

      tn = dt0:Analysis[rn];

      dt1 = Data Table( "result table" ) <<

      Subset(

       Output Table( tn[1] ),

       selected columns( 0 ),

       Selected Rows( 0 ),

       Rows( rn )

      );

      dt2 = dt1 << columns(

       :Result 1,

       :Result 2,

       :Result 3,

       :Result 4,

       :Result 5,

       :Result 6,

       :Result 7,

       :Result 8,

       :Result 9

      )`;

      graph1 = Expr(

       dt2 << Overlay Plot(

        Y( Column( 2 ) ),

        Separate Axes( 1 ),

        Connect Thru Missing( 1 )

       )

      );

      journgraph1 = Eval( graph1 ) << Get Journal;

      New Window( "Report Window For " || tn[1],

       Text Box( "Graph of " || tn[1] ),

       Journal Box( journgraph1 )

      );

      Close( dt1, no save );

      Close( dt2, no save );

     )

    )

   )

  )

),

Set Row States( [0, 0, 0, 0, 1] )

)

This is the script to paste into the formula column

(1);


();



( Selected( Row State() )



(


(



(1);


(1);


=current data table();


=dt0<<get selected rows;


=dt0:Analysis[rn];


=Data Table( "result table" ) << Subset(


1] ),


0),


0 ),


//,invisible


;


=dt1 << Transpose(



:Result 1,


:Result 2,


:Result 3,


:Result 4,


:Result 5,


:Result 6,


:Result 7,


:Result 8,


:Result 9,


:Column 11


,


:Analysis[rn] ),//this doesn't get translated in the formula



1]||" for graph" )//,invisible


;



=expr(dt2<<Overlay Plot( Y( column(2) ), Separate Axes( 1 ), Connect Thru Missing( 1 ) ));


=eval(graph1)<<Get Journal;


("Report Window For "||tn[1], Text box("Graph of "||tn[1]), Journal Box (journgraph1));




(dt1, no save);


(dt2, no save);





//end of parse


//end of eval


;//end of if

7 REPLIES
ms

Super User

Joined:

Jun 23, 2011

If you mean triggering a script action by selecting a row in the table I suggest you take a look at this demo in the JMP file exchange. Any type of action that jsl is capable of can be invoked by selecting a row using the trick Ian Cox uses in that demo.

In his example the scripts are actually strings within table cells but it should be possible to invoke table scripts or why not standalone scripts using the Include() function.

For example try the column formula below in a hidden column to run scripts named exactly as the cell content in a character column "testname".

If(Selected(Row State(Row())), Include("yourpath" || Eval(:testname) || ".jsl"); 1, 0)

If testname in row three is "ANOVA" then a script ANOVA.jsl saved in a directory with path "yourpath" will be run when the third row is selected (manually but also by script I'd guess).

olivia_manning

Community Trekker

Joined:

Jun 20, 2012


Yes, that's exactly what I want to do.

The problem I'm having is that I need to get that test name back into the JMP script so that I can send it to R for my function to do it's job...

I've tried this:

In an additional column in my table:

If(Selected(Row State(Row())), Include("C:/Users/....jsl" || Eval(Parse(:TestName)) || ".jsl"); 1, 0)

And then in the script page:

tname = TestName << Get text;

rconn << Send(tname,R Name("tname"));

I'm obviously doing something wrong as it's not working...

ms

Super User

Joined:

Jun 23, 2011

First, check the path string. The first argument should include only the path to the script directory and hence end with a / (slash).

To pass the selected TestName to variable you need to be more explicit:

tname=:TestName[(current data table()<<get selected rows)[1]]

This code can be run by the column formula (see example below) or in the called script.

If(Selected(Row State(Row())), tname=:TestName[(current data table()<<get selected rows)[1]]; Include("C:/Users/..../your_script_folder/" || Eval(Parse(:TestName)) || ".jsl"); 1, 0);

olivia_manning

Community Trekker

Joined:

Jun 20, 2012

Thanks

I'm having problems adding all of this to my script.

What I have been trying to do is get the table and then add on a column with

     "Selected(Row State(Row())), tname=:TestName[(current data table()<<get selected rows)[1]]; 

     Include("C:/Users/..../Tests/" || Eval(Parse(:TestName)) || ".jsl"); 1, 0);"

Here "Tests" is my second script folder (the one that will be used when the user clicks on a row in the table).

My first problem is that I can't find a way to do this as the quotation marks are causing problems, and the second is that what I'm doing here is all part of a tool that I want other people I work with to be able to use. Will that be possible seeing that I now have a second script that is being accessed via its filepath (the script is on my desktop)?

Again, thanks for your help

Olivia

Solution

The script below is for a table that has a formula column with a script to make graphs from rows.

When a row is selected, the contents of several of the columns for the selected row are made into a subset table, which is transposed so it can be graphed with an overlay plot. The original script that is in the formula column starts out looking a lot different, and its inclucded below the table script.

(copy the table script into a script window and run the script)

New Table( "result table",

Add Rows( 5 ),

New Column( "Analysis",

  Character,

  Nominal,

  Set Values( {"ANOVA", "Apple", "Bannana", "Orange", "Peach"} )

),

New Column( "Result 1",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 2",

  Numeric,

  Continuous,

  Format( "", 9 ),

  Formula( Random Uniform() )

),

New Column( "Result 3",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 4",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() ),

  Set Selected

),

New Column( "Result 5",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 6",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 7",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 8",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Result 9",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula( Random Uniform() )

),

New Column( "Column with Formula to make graphs",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Formula(

   If( Selected( Row State() ),

    Eval(

     Parse(

      Names Default To Here( 1 );

      Clear Symbols( 1 );

      dt0 = Current Data Table();

      rn = dt0 << get selected rows;

      tn = dt0:Analysis[rn];

      dt1 = Data Table( "result table" ) <<

      Subset(

       Output Table( tn[1] ),

       selected columns( 0 ),

       Selected Rows( 0 ),

       Rows( rn )

      );

      dt2 = dt1 << columns(

       :Result 1,

       :Result 2,

       :Result 3,

       :Result 4,

       :Result 5,

       :Result 6,

       :Result 7,

       :Result 8,

       :Result 9

      )`;

      graph1 = Expr(

       dt2 << Overlay Plot(

        Y( Column( 2 ) ),

        Separate Axes( 1 ),

        Connect Thru Missing( 1 )

       )

      );

      journgraph1 = Eval( graph1 ) << Get Journal;

      New Window( "Report Window For " || tn[1],

       Text Box( "Graph of " || tn[1] ),

       Journal Box( journgraph1 )

      );

      Close( dt1, no save );

      Close( dt2, no save );

     )

    )

   )

  )

),

Set Row States( [0, 0, 0, 0, 1] )

)

This is the script to paste into the formula column

(1);


();



( Selected( Row State() )



(


(



(1);


(1);


=current data table();


=dt0<<get selected rows;


=dt0:Analysis[rn];


=Data Table( "result table" ) << Subset(


1] ),


0),


0 ),


//,invisible


;


=dt1 << Transpose(



:Result 1,


:Result 2,


:Result 3,


:Result 4,


:Result 5,


:Result 6,


:Result 7,


:Result 8,


:Result 9,


:Column 11


,


:Analysis[rn] ),//this doesn't get translated in the formula



1]||" for graph" )//,invisible


;



=expr(dt2<<Overlay Plot( Y( column(2) ), Separate Axes( 1 ), Connect Thru Missing( 1 ) ));


=eval(graph1)<<Get Journal;


("Report Window For "||tn[1], Text box("Graph of "||tn[1]), Journal Box (journgraph1));




(dt1, no save);


(dt2, no save);





//end of parse


//end of eval


;//end of if

olivia_manning

Community Trekker

Joined:

Jun 20, 2012

Thanks, that really helped! I have finally managed to get it to work

landon

Super User

Joined:

Jun 23, 2011

I really enjoyed implementing this idea.  If my script can handle multiple rows being selected (like for some combined plot) is there a way to wait for all the rows to be selected (like when holding down the cntrl key) before firing off the script?

For example, if I want to select rows 1,3,5... currently I have to select row 1, which immediately fires the script, then close the window generated from the script, then select row 3 (holding down the cntrl key), which immediately fires the script, then close the window generated from the script (with 1 and 3 combined), then select row 5 (holding down the cntrl key)... which finally fires the script with the combined 1, 3, and 5.  Would it be possible to select 1, 3, and 5... and then fire off the script?