Re: DynamicModule question

*To*: mathgroup at smc.vnet.net*Subject*: [mg88611] Re: DynamicModule question*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Fri, 9 May 2008 07:17:53 -0400 (EDT)*Organization*: The Open University, Milton Keynes, UK*References*: <fvudm6$eb5$1@smc.vnet.net>

J. McKenzie Alexander wrote: > Can someone please explain to me why the following happens? It's a > silly little example to illustrate a problem I ran into recently... > > First, evaluate the following in separate cells: > > Needs["PieCharts`"]; > > data = {.25, .75} > > Then evaluate the following: > > DynamicModule[{size = 300}, > Column[{ > Slider[Dynamic[size], {100, 500}], > Dynamic[PieChart[data, ImageSize -> size]] > }] > ] > > Notice that you can not only resize the graphic by dragging the > slider, but if you change the definition of data, that's reflected > automatically in the graphic as well. > > However, suppose you wrap the DynamicModule in a function like so: > > foo[data_] := DynamicModule[{size = 300}, > Column[{ > Slider[Dynamic[size], {100, 500}], > Dynamic@PieChart[data, ImageSize -> size] > }] > ] > > Now evaluate > > foo[ data ] > > If you change the definition of data in the notebook, the second > DynamicModule doesn't update the pie charts. I don't understand what > breaks when you wrap the DynamicModule in a function definition. Try Dynamic@foo[data] Now, why Dynamic is needed here? I do not know. Looking at the expressions in the output cells (Shift + Cmd + E ) for the code generated by entering directly the DynamicModule or by using a function both resulting expressions look very similar (even identical, as far as I can trust my sight :-) Regards, -- Jean-Marc