This question is related to another question of mine : How can I add a checkbox to a Manipulate expression?, but I'm still unable to make the checkbox to work properly. Here's a MWE code, from my much bigger version (I think that this code is pretty cool, since it also shows how to add an information display on top of a 3D graphics) :
Info[frequency_] := Inset[Grid[{
{Row[{"The frequency :"}], Row[{NumberForm[frequency, {12, 3}], " unit"}]},
{Row[{"Another data :"}], Row[{NumberForm[4.56323, {12, 3}], " unit"}]}
},
BaseStyle -> {FontSize -> 12, FontFamily -> "Courier"},
Alignment -> Right, Frame -> All, FrameStyle -> {Thick, LightGray}
], {0.8, 0.1}]
Manipulate[Show[
ParametricPlot3D[{Sin[3 frequency t], Cos[5 frequency t], Sin[2 t]}, {t, 0, 2 Pi}],
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
Epilog -> Which[c == 0, {}, c == 1, Info[frequency]],
SphericalRegion -> True,
ImageSize -> {600, 600}],
Row[{Checkbox[Dynamic@c, {0, 1}], Spacer[5], Dynamic@Switch[c, 0, "State OFF", 1, "State ON"]}],
{{frequency, 1, "Test"}, 0, 4, 0.01, Appearance -> "Labeled"}]
The code above works partially, but in the case of my full code the output flashes with an error color (immediately after compilation), without giving any error message ! I suspect that's because the checkbox doesn't have an initial state value. So what is wrong with the code ? How can I define the initial value of the checkbox ?
If you compile the small code above, you shouldn't get any error message. But the checkbox may be checked ON or OFF, depending of what you do with with it, before each compilation. It is not behaving correctly.
The checkbox is used to turn ON/OFF an information display on top of the 3D graphics. By default, it should be OFF. The small text string ("State ON/OFF") should be displayed at the right of the checkbox, in the manipulate panel. Maybe there's a simpler way of doing this ?
Dynamic@
on yourWhich
in theEpilog
. That seems to be causing me trouble when I try to play with this. $\endgroup$Compile[...]
, or do you just mean running the code through the MMA front end? You could try initializingc
with a value before theManipulate
, etc. etc. Without a MWE that reproduces the problem you're having it'll be tough to help. $\endgroup$