1
$\begingroup$

I have a RadioButtonBar with a selection

x = None;
{RadioButtonBar[Dynamic[x], {lt, le, eq, gt, ge}], Dynamic[x]}

Once a radio button is selected, I would like to convert the selection to a conditional operator, e.g., eq is ==. Then use the operator to select rows in a data table via Select. I have tried ToExpression and Symbol without much success. What are good ways to do this? I have not been able to find anything on the web to do this. There are warnings not to use eval as a general practice. Is that the way to go? Thanks.

$\endgroup$
1
$\begingroup$

You can use rules in the second argument of RadioButtonBar to specify the values and labels for each button:

enter image description here

x = None;
t = 3;

{RadioButtonBar[Dynamic[x], 
   {Less -> lt, LessEqual -> le, Equal -> eq, Greater -> gt, GreaterEqual -> ge}], 
 Dynamic[x], 
 Dynamic @ Select[Range[10], x[#, t] &]} // Column

enter image description here

Note: From the title of your question you probably meant to make labels strings as in

RadioButtonBar[Dynamic[x], 
  {Less -> "lt", LessEqual -> "le", Equal -> "eq", Greater -> "gt", GreaterEqual -> "ge"}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.