I'm trying to implement a "fancy control" in my .cdf using Manipulate
... My intention is to have a control in form of a table of values (I would prefer Grid), with conditional formatted background of cells, where the end-user should be able to choose and select a row. The data in the selected row should be allocated to a variable and used for further calculations.
So far I was able to prepare everything (using also the great answer to one of my other questions concerning conditional formatting), but I don't seem to find a way to use the table of values as input (Control) in Manipulate
.
Here my sample of code:
Manipulate[
cG = 78500;
len = 400;
s[x_] := (2105 - 780*Log10[x])/Sqrt[3];
t[x_] := 360*s[x]*len/(Pi*cG*x);
data = Prepend[
Transpose[{Table[d, {d, 1., 10., 0.1}],
Table[s[d], {d, 1., 10., 0.1}],
Table[t[d], {d, 1., 10., 0.1}]}],
{"d", "S", "T"}];
crules = Table[n -> If[data[[n, 3]] < 90., LightRed,
If[data[[n, 3]] < 120., LightYellow, LightGreen]],
{n, 1,Length[data]}];
maintable = Grid[data, Frame -> All, Background -> {None, crules}];
main = Pane[maintable, ImageSize -> {All, 150}, Scrollbars -> True];
Print[sel],
Control[{sel, ListPicker[Dynamic[sel], main]}]]
The table to choose from should look like this:
I would appreciate some advice at this point. Thanks a lot in advance!
.......
Based on m_goldberg answer, I was able to further match the appearance of the table to my needs:
s[x_] := (2105 - 780*Log10[x])/Sqrt[3];
With[{cG = 78500, len = 400}, t[x_] := 360*s[x]*len/(Pi*cG*x)];
data = Transpose[{Table[d, {d, 1., 10., 0.1}],
Table[s[d], {d, 1., 10., 0.1}], Table[t[d], {d, 1., 10., 0.1}]}];
crules = Table[
n -> If[data[[n, 3]] < 90., LightRed,
If[data[[n, 3]] < 120., LightYellow, LightGreen]], {n, 1,
Length[data]}];
With[{cellw = 6},
dataGrid =
Column[{
Pane[
Grid[{{"d", "S", "T"}}, Frame -> All, Background -> LightGray,
ItemSize -> cellw]],
Pane[NumberForm[
Grid[data, Frame -> All, Background -> {None, crules},
ItemSize -> cellw], {10, 3}], ImageSize -> {All, 350},
AppearanceElements -> {}, Scrollbars -> {False, True}]},
Dividers -> All,
ItemSize -> {{21.2, 5}}]];
Manipulate[dataGrid, SaveDefinitions -> True]
Now it looks like this:
I used though Column
instead of Grid
, cause it seemed easier to me to align the vertical dividers.
I left the other task out (ability to select data from table and assign it to a variable), as it looks indeed much more complex. I use the table just to visualize the data and I will input separately the values for further calculations. Thanks a lot @m_goldberg.
DynamicModule[{ data = RandomReal[1, {3, 10}], x, result = "" }, Grid[{{ ListPicker[Dynamic@x, data], Button["plot", result = ListPlot@x] }, {Dynamic@result, SpanFromLeft} }] ]
- what do you want to change/add there? $\endgroup$ – Kuba♦ Jun 3 '16 at 10:50Manipulate
(tillPrint
) and evaluate it, you will see the targeted shape of the table. $\endgroup$ – Conrad Jun 3 '16 at 11:45