# TogglerBar with arbitrary dimensions

I'd like to split my TogglerBar into several rows, with it's length given in a list.

I found the Appearance options, but they only allow one fixed horizontal/vertical dimension. Which is why I thought splitting my TogglerBar up in several pieces would be the way to go.

data = {2, 3, 1}
Manipulate[Boole @ MemberQ[x, #] & /@ Range@Total @ data,
{x, {1, 2}, ControlType -> TogglerBar},
{x, {3, 4, 5}, ControlType -> TogglerBar},
{x, {6}, ControlType -> TogglerBar}]


How can I write this, so that it'll still work when I change the length of data? E.g. to data = {1, 1, 2, 2}.

• Sorry about that! So currently I'm getting 3 TogglerBars with the length 2, 3 respectively 1, as given by the list data. This list is not always going to be the same though. So I'd like to write Manipulate in a way, that I can have any dataI want and get a number of toggler bars given by the number of elements in data, with the number of togglers given by the numbers in data. Please let me know if it's still confusing. – Jason Jan 15 '15 at 13:52

Something like this?:

data = {1, 1, 2, 2};

DynamicModule[{max = Tr @ data, x},
Manipulate[
Normal @ SparseArray[Thread[x -> 1], max],
##
] & @@
Thread[{x, InternalPartitionRagged[Range@max, data],
ControlType -> TogglerBar}]
]


• Yes, this is it! Can I ask another question though? I was using the output of manipulate to change the opacity of a number of graphs in my ListPlotin order to toggle their visibility. I'm not that advanced with Mathematica yet and have a hard time implementing your code into what I wanted to achieve. Could you help me get into the right direction? This is what I was going for. I was now trying to break my ToggleBar` into several parts. – Jason Jan 15 '15 at 18:19
• I got it to work! Thank you for the help! – Jason Jan 16 '15 at 13:01
• @Jason Good. Sorry I wasn't around sooner to help, but working through it yourself was probably a better learning experience anyway. – Mr.Wizard Jan 16 '15 at 14:04
• Can I ask, I'd love to learn the more advanced language Syntax using @, @@, #&, /@ etc. I found a stackexchange post where their meanings are listed. Do you know if there are any tutorials on this? Or is there a way to practice their usage, or see examples where they are used in a well written way? – Jason Jan 16 '15 at 15:52
• @Jason There is no short-cut to learning the language in my opinion. In that post each of the operators has a [ref] link that will take you to its documentation page. If you prefer a more linear tutorial I recommend Leonid's online book but I warn you that despite the name "introduction" it is quite thorough. Other than these general guidelines anything I can think to point you toward would be more specific, such as my own answer to (46238). – Mr.Wizard Jan 16 '15 at 16:07