cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
KinKame
Level IV

creation of link

Hello

I would like to know if it would be possible getting link information and a title to create a new link based on those 2 information

Header 1Header 2Header 3
Link (http// ....)NAMENAME
8 REPLIES 8
txnelson
Super User

Re: creation of link

Is your question:

If I have a URL link in a column in a data table, and a title in another column in a data table, can I put that information together to come up with a new URL link in a third column?

If that is the question, the answer is yes, but I am not sure that is what you are asking.  Can you please provide more specifics on what you are asking?

Jim
KinKame
Level IV

Re: creation of link

more specific

I have a table with

column 1 --> link (for example: https://community.jmp.com/)

column 2 --> name (for example JMP)

I would like to create column 3 as

column 3 --> JMP (similar to HYPERLINK function in excel)

reason is sometimes http are very long and not usable for viewing.

If not possible I can go thru excel no issue but would prefer to have all in JMP

pmroz
Super User

Re: creation of link

This will do it:

// Assumes that you have a column called Header 3 with a description of what to get

// and another column called Header 1 with the actual URL   

dt << new column("Select Logic", character,

    formula(

        dst = current data table();    // Need a local variable because this is a formula

        If (Selected(),

            sel_cols = dst << get selected columns;

            sel_rows = dst << get selected rows;

            if (islist(sel_cols),

// then

if (nitems(sel_cols) == 1 & nrows(sel_rows) == 1 &

uppercase(char(sel_cols[1])) == "Header 3",

// then

my_url = column(dst, "Header 1")[sel_rows[1]];

web(my_url);    // Does the actual work

);    // end 1 col, 1 row, AER col

            );    // end islist

        );        // end if selected

        "x";    // Need a dummy value for the column

    );    // end forumula

);    // end new column

column(dt, "Select Logic") << hide;

KinKame
Level IV

Re: creation of link

ok got it. thank you very much

I did not know this web function but seems pretty cool.

KinKame
Level IV

Re: creation of link

Ok PMorz,

it doesnt really work.

I can actually create a logic column filled with "x"...

any hint?

pmroz
Super User

Re: creation of link

Sorry - didn't test my logic.  This code will work:

dt = New Table( "Example Web Logic", Add Rows( 3 ),

    New Column( "Click for Web", Character, "Nominal",

        Set Values( {"JMP", "Google", "JMP Community"} )

    ),

    New Column( "Link", Character, "Nominal", Hide,

        Set Values(

            {"http://www.jmp.com", "http://www.google.com",

            "https://community.jmp.com/community/discussions"}

        )

    )

);

dt << new column("Select Logic", character,

    formula(

        dst = current data table();    // Need a local variable because this is a formula

        If (Selected(),

            sel_cols = dst << get selected columns;

            sel_rows = dst << get selected rows;

            if (islist(sel_cols),

            // then

                if (nitems(sel_cols) == 1 & nrows(sel_rows) == 1 &

                    (sel_cols[1] << get name) == "Click for Web",

                // then

                    my_url = column(dst, "Link")[sel_rows[1]];

                    web(my_url);    // Does the actual work

                );    // end 1 col, 1 row, AER col

            );    // end islist

        );        // end if selected

        "x";    // Need a dummy value for the column

    ); // end forumula

);    // end new column

column(dt, "Select Logic") << hide;

ian_jmp
Staff

Re: creation of link

Building on Peter's thoughts, you could also use the 'row state handler':

New Column( "Link",

Character,

"Nominal",

Value Labels(

{"http://www.google.com" = "Google", "http://www.jmp.com" = "JMP",

"https://community.jmp.com/community/discussions" = "Community"}

),

Use Value Labels( 1 ),

Set Values(

{"http://www.jmp.com", "http://www.google.com",

"https://community.jmp.com/community/discussions"}

)

)

);

// Follow the link in each row currently selected

followLinks =

Function({x},

ForEachRow(

If( Selected( Row State()), Web(Column(dt, "Link")[Row()]) );

);

);

// Assign the handler to the table

rsh = dt << MakeRowStateHandler(followLinks);

(In passing, I note that an expression column does not seem to allow the use of value labels).

pmroz
Super User

Re: creation of link

A row state handler is a good idea.  I think I developed my approach before that came available.  It's a cleaner solution.