1
$\begingroup$

By default, when you click the small "+" symbol, at the right of a slider (in Manipulate and Animate), you get an input field and several buttons (play, pause, etc). How do you remove all buttons for all the sliders in a Manipulate box, except the input fields ?

The documentation isn't obvious at all for customization like this, and searching the site didn't helped much. Sorry if I missed something related.

$\endgroup$
  • $\begingroup$ So you want the slider AND the input field? If you can get by without the input field and work just with the slider, you could use ControlType -> Slider. $\endgroup$ – MarcoB Mar 13 '16 at 1:40
  • $\begingroup$ @MarcoB, I still need the input field for values that are hard to select with a slider. $\endgroup$ – Cham Mar 13 '16 at 1:50
  • $\begingroup$ Related: (28768). $\endgroup$ – MarcoB Mar 13 '16 at 2:07
  • $\begingroup$ Manipulate[ Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 6, AppearanceElements -> {"InputField", "Slider"}}] ? $\endgroup$ – Algohi Mar 13 '16 at 2:27
  • $\begingroup$ @Algohi, nice ! This is working ! Is there a way to define these options "globaly" inside the Manipulate code, without having to add these options to each slider separately ? $\endgroup$ – Cham Mar 13 '16 at 2:35
2
$\begingroup$
With[{maniOpts = Sequence[
    Appearance -> {"Labeled", "Open"}, 
    AppearanceElements -> {"InputField", "Slider"}, ImageSize -> Large
    ]
  },
 Manipulate[
   Plot[Sin[x (1 + a x)]/b, {x, 0, 6}], 
  {a, 0, 6, maniOpts}, 
  {b, 1, 5,  1, maniOpts}]
 ]

This is what I do in similar cases.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Why the With ? I tried using just maniOpts = Sequence[ Appearance -> {"Labeled", "Open"}, AppearanceElements -> {"InputField", "Slider"}, ImageSize -> Large ];, and it's working great, apparently after a first try. $\endgroup$ – Cham Mar 13 '16 at 14:29
  • $\begingroup$ @Cham Manipulate is meant to work across MMA sessions, so if you are not including maniOpts inside or injecting those options directly, maniOpts will be forgotten when you open this cdf/notebook in fresh session. So maybe it's not necessary but I do this from habit. $\endgroup$ – Kuba Mar 13 '16 at 14:39
  • $\begingroup$ I'm not sure to understand. These options are defined only for this particular Manipulate box. If I close this notebook or if I open another nootebook with another Manipulate, it is normal that everything is forgotten by MMA. Compiling a given code would erase all the previous definitions, since I use Clear["Global`*"] at the beginning of all of my projects. Well, this is the way I work with MMA. Maybe this isn't ideal ? Is there a potential conflict/problem I'm not aware of, with this method ? $\endgroup$ – Cham Mar 13 '16 at 14:45
  • $\begingroup$ @Cham Manipulate is HoldAll so if you just put there Global`maniOpts its definition won't be found when you open notebook in fresh session, unless you evaluate whole notebook but the point is to have self contained Manipulate output. You can read more about related things in reference.wolfram.com/language/tutorial/…, especially on FE ownership of DynamicModule variables. $\endgroup$ – Kuba Mar 13 '16 at 16:13
  • $\begingroup$ Kuba, the document you linked cannot be found. $\endgroup$ – Cham Mar 13 '16 at 16:18
2
$\begingroup$

Roll your own controls:

Manipulate[
  a b c d,
  Grid[{
    {Labeled[Slider[Dynamic[a], {0, 100}], "a =", Left],
     InputField[Dynamic[a], ImageSize -> Tiny]},
    {Labeled[Slider[Dynamic[b], {-50, 50}], "b =", Left], 
     InputField[Dynamic[b], ImageSize -> Tiny]},
    {Labeled[Slider[Dynamic[c], {-10, 30}], "c =", Left],
     InputField[Dynamic[c], ImageSize -> Tiny]},
    {Labeled[Slider[Dynamic[d], {0, 1}], "d =", Left],
     InputField[Dynamic[d], ImageSize -> Tiny]}
  }]
]

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ The InputField would replace the slider's label. This is fine. These elements would be placed inside a Row directive to make a line. But how do you place several of them (Slider + InputField) on top of each other ? $\endgroup$ – Cham Mar 13 '16 at 2:28
  • $\begingroup$ @Cham Yes, you can arrange their position as you wish using e.g. Row. But what do you mean by on top of each other? $\endgroup$ – MarcoB Mar 13 '16 at 2:32
  • $\begingroup$ I mean a vertical stack of standard sliders (as what is done by default), but each one having its Input field on their right using Row. $\endgroup$ – Cham Mar 13 '16 at 2:37
  • $\begingroup$ @Cham Take a look at the new version of my answer. $\endgroup$ – MarcoB Mar 13 '16 at 2:52
  • $\begingroup$ It's all working great ! I prefer Algohi's settings, since it's making my code much simpler and easier to understand. Both answers are good, though. Thanks a lot ! $\endgroup$ – Cham Mar 13 '16 at 2:59
2
$\begingroup$

If you are okay with a general setting, you can do it like this:

SetOptions[Manipulator, AppearanceElements -> {"InputField", "Slider"}];
Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 6}]

You can either save the options and return them back:

saveoption = Options[Manipulator];
SetOptions[Manipulator, saveoption];

Or you can use ParallelEvaluate to get fresh kernel:

SetOptions[Manipulator, First@ParallelEvaluate[Options[Manipulator]]]

Or as J. M. mentioned, use:

SetOptions[Manipulate, AppearanceElements -> Automatic]

example Manipulate

| improve this answer | |
$\endgroup$
  • $\begingroup$ Very nice ! This would simplify my code a lot, with ImageSize -> Large, Appearance -> {"Labeled", "Closed"}, added to the SetOptions. Can this SetOptions be reset using Clear["Global`*"] ? $\endgroup$ – Cham Mar 13 '16 at 2:50
  • 1
    $\begingroup$ @Cham, use SetOptions[Manipulate, AppearanceElements -> Automatic] to reset back to the default. $\endgroup$ – J. M.'s technical difficulties Mar 13 '16 at 2:55
  • $\begingroup$ Aw, I see that it's also resetting all the other Manipulate codes I've done. So this cannot be set locally, for a given Manipulate ? Do I have to add SetOptions[Manipulate, AppearanceElements -> Automatic] to all of my other Manipulate codes ? $\endgroup$ – Cham Mar 13 '16 at 3:02
  • 2
    $\begingroup$ @Cham, just append the options if you only want it to apply to a single Manipulate[]: Manipulate[(* stuff *), Appearance -> {"Labeled", "Closed"}, AppearanceElements -> {"InputField", "Slider"}, ImageSize -> Large]. $\endgroup$ – J. M.'s technical difficulties Mar 13 '16 at 3:09
  • $\begingroup$ It appears to work, but Appearance and ImageSize are shown in red in my code ! The compilation appears to be normal, and no warning/error messages. ?? $\endgroup$ – Cham Mar 13 '16 at 3:13

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.