4

I need your help with making a slider invisible and visible in a Manipulate. Here is my code:

Manipulate[{}, 
  {x, 0, 1}, 
  {y, 0, 1}, 
  {visible, 
    {"only x-slider visible", "only y-slider visible", "both visible"}, 
    ControlType -> PopupMenu}]

The PopupMenu shows how I want it to function.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Manu
  • 337
  • 2
  • 10

2 Answers2

5

Here is an option:

Manipulate[{},
  Dynamic@If[visible != "hide x-slider",
             Control[{x, 0, 1}],
             Invisible@Control[{x, 0, 1}]], 
  {visible, {"hide x-slider", "show x-slider"}, ControlType -> PopupMenu}]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Ok, the part DynamicWrapper[Dynamic@If[]] I see nowhere before. Thanks for your help. Is there any other possibility to solve that problem? I can use x only as a normal slider, but can't open this slider with the plus... – Manu Jan 08 '14 at 17:07
  • @Manu See edit please – Dr. belisarius Jan 08 '14 at 17:42
  • Ok, very well :-) Thanks – Manu Jan 08 '14 at 17:47
  • I have another possibility without using Invisible@Control[]: Manipulate[{}, Dynamic@If[visible != "hide x-slider", Column[{Control[{x, 0, 1}], Control[{y, 0, 1}]}], Control[{y, 0, 1}]], {visible, {"hide x-slider", "show x-slider"}, ControlType -> PopupMenu}] – Manu Jan 08 '14 at 18:13
  • @Manu I used Invisible[] on purpose to preserve the appearance of the manipulate dialog – Dr. belisarius Jan 08 '14 at 18:18
  • I know, you only answered my question – Manu Jan 08 '14 at 18:25
4

A couple more ways.

PaneSelector, with a blank Row:

Manipulate[{x, y},
 PaneSelector[{True -> Control[{x, 0, 1}], False -> Row[{}]}, 
   Dynamic[visible != "only y-slider visible"]],
 PaneSelector[{True -> Control[{y, 0, 1}], False -> Row[{}]}, 
   Dynamic[visible != "only x-slider visible"]],
 {visible, {"only x-slider visible", "only y-slider visible", 
            "both visible"}, ControlType -> PopupMenu}]

Dynamic switch between Identity & Invisible:

Manipulate[{x, y},
 Dynamic[If[visible != "only y-slider visible", Identity, Invisible]@
   Control[{x, 0, 1}]],
 Dynamic[If[visible != "only x-slider visible", Identity, Invisible]@
   Control[{y, 0, 1}]],
 {visible, {"only x-slider visible", "only y-slider visible", 
            "both visible"}, ControlType -> PopupMenu}]

Mathematica graphics Mathematica graphics

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • So now I have a lot of possibilitys :-) – Manu Jan 08 '14 at 22:46
  • @Manu, make sure you've got that: Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – garej Aug 07 '15 at 21:44