BookmarkSubscribeSubscribe to RSS Feed
RSantana

New Contributor

Joined:

Sep 17, 2018

Adding Images to A Data Table From a Directory

Friends, I am running JMP12 and I would like to add a series of PNG images to my data table.  I would like to do this so that I can use them as labels on a scatterplot of statistical mean-matching flags and invoke the PNG (an image of a control limit chart) by hovering the mouse over the value of each flag.  I found an SAS video by Gail Massari importing state bird pictures from a wikipedia web URL; different than him, my images are in a folder, on a local hard drive. 

 

I have tried the instruction:

{"",{ newimage(open( "drive:\file path\filename.png",png))}" as a entry in each respective row but all I get in return is an "Empty()" output.

 

I am new to JSL scripting and I have run out of ideas.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
gzmorgan0

Community Trekker

Joined:

Jul 25, 2016

Solution

Re: Adding Images to A Data Table From a Directory

RSantana, Gail's video was demonstarting how to get pics from URLs, not embedded pictures.

 

Try the script that startw with Names default to Here(1). It was created in JMP 12.

 

Note, if all of your pictures are of the same type then you can simplify lines 11 and 12. Suppose all your pictures are png, then you do not need line 11: _typ = word() and line 12 you can remove the Eval( EvalExpr() ) functions. I needed it for this example because the sample images have different types and in JMP 12, the open would not evaluate the variable _ext; it required that the expression be substituted then evaluated.  

This would be the simplified line 12    tp = Open("$Sample_images/"||_fid[i], "png" );

 

Copy and paste this into a JMP script window, run it then hover over the points. One final comment this is embedding each picture's "code" into your table column.

 

 

Names Default to Here(1);

_fid = Files in Directory("$sample_images");
nr = nitems(_fid);
//Create a table
dt = New Table("demo",add rows(nr),
New Column("X", <<set Values(1::nr)), New Column("Y", <<set Values(1::nr)),
  New Column("pics", Expression)  );
 
for(i=1, i<=nr, i++,
  _typ = word(2,_fid[i],".");
  Eval(Eval Expr(tp = Open("$Sample_images/"||_fid[i], expr(_typ) )));	
  dt:pics[i] = new image(tp)	
);
dt:pics << label(1);

biv = dt<< Bivariate( Y(:Y), X(:X)); 
gzmorgan0

Community Trekker

Joined:

Jul 25, 2016

Solution

Re: Adding Images to A Data Table From a Directory

Is the full path in a separate column, or do you have a column for path and a column for file name?

Suppose it is a column named :Path. Since they are all png files then 

 tp = Open( :Path[i], "png" );

 

If you have two columns :Dir and :Name use something like this, if there is no trailing slash for the dir name

 tp = Open( :Dir[i] || "\" || :Name[i], "png" );

Older versions of JMP required an eval()

 

 tp = Open( eval( :Dir[i] || "\" || :Name[i] )  , "png" );

 

Try it out before running your script , run just one line replacing i with a number to make sure you have the file pathname correct.

 

6 REPLIES
Highlighted
gzmorgan0

Community Trekker

Joined:

Jul 25, 2016

Solution

Re: Adding Images to A Data Table From a Directory

RSantana, Gail's video was demonstarting how to get pics from URLs, not embedded pictures.

 

Try the script that startw with Names default to Here(1). It was created in JMP 12.

 

Note, if all of your pictures are of the same type then you can simplify lines 11 and 12. Suppose all your pictures are png, then you do not need line 11: _typ = word() and line 12 you can remove the Eval( EvalExpr() ) functions. I needed it for this example because the sample images have different types and in JMP 12, the open would not evaluate the variable _ext; it required that the expression be substituted then evaluated.  

This would be the simplified line 12    tp = Open("$Sample_images/"||_fid[i], "png" );

 

Copy and paste this into a JMP script window, run it then hover over the points. One final comment this is embedding each picture's "code" into your table column.

 

 

Names Default to Here(1);

_fid = Files in Directory("$sample_images");
nr = nitems(_fid);
//Create a table
dt = New Table("demo",add rows(nr),
New Column("X", <<set Values(1::nr)), New Column("Y", <<set Values(1::nr)),
  New Column("pics", Expression)  );
 
for(i=1, i<=nr, i++,
  _typ = word(2,_fid[i],".");
  Eval(Eval Expr(tp = Open("$Sample_images/"||_fid[i], expr(_typ) )));	
  dt:pics[i] = new image(tp)	
);
dt:pics << label(1);

biv = dt<< Bivariate( Y(:Y), X(:X)); 
RSantana

New Contributor

Joined:

Sep 17, 2018

Re: Adding Images to A Data Table From a Directory

This is exactly what I need and the solution is simply elegant; I am very appreciative of your time and of your help.

 

Now the challenge...

I have my PNG files in 46 individual folders and the PNG files share the same name; for example I have "graph30.png" repeated 20-30 times but each file is saved in a different folder because it is an image of a different control limit chart.  I already have the path\filename for each as a discrete column in my data table. 

 

What would be the best way look for each graphXX.png based on the specific path\filename already available in a contiguous column?

gzmorgan0

Community Trekker

Joined:

Jul 25, 2016

Solution

Re: Adding Images to A Data Table From a Directory

Is the full path in a separate column, or do you have a column for path and a column for file name?

Suppose it is a column named :Path. Since they are all png files then 

 tp = Open( :Path[i], "png" );

 

If you have two columns :Dir and :Name use something like this, if there is no trailing slash for the dir name

 tp = Open( :Dir[i] || "\" || :Name[i], "png" );

Older versions of JMP required an eval()

 

 tp = Open( eval( :Dir[i] || "\" || :Name[i] )  , "png" );

 

Try it out before running your script , run just one line replacing i with a number to make sure you have the file pathname correct.

 

RSantana

New Contributor

Joined:

Sep 17, 2018

Re: Adding Images to A Data Table From a Directory

gzmorgan, this was awesome and worked like a charm. Big thank you!!

A final question,
Are journals in JMP.12 unable to display labels as you select or hover over data points in graphs?
gzmorgan0

Community Trekker

Joined:

Jul 25, 2016

Re: Adding Images to A Data Table From a Directory

Journals are snapshots of your display.  One option is to save as a .JRP with embedded tables. Then when another opens it the underlying table and report is active.

 

In JMP 13 and 14 Save as Interactive HTM saves the display and the labels are embedded. 

RSantana

New Contributor

Joined:

Sep 17, 2018

Re: Adding Images to A Data Table From a Directory

Again, thank you for your time.

Interacting in this community has been a delightful learning experience.