Re: DynamicModule question
- To: mathgroup at smc.vnet.net
- Subject: [mg88568] Re: DynamicModule question
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 9 May 2008 03:20:57 -0400 (EDT)
- Organization: Uni Leipzig
- References: <fvudm6$eb5$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi,
try
SetAttributes[foo, HoldAll]
foo[data_] :=
DynamicModule[{size = 300},
Column[{Slider[Dynamic[size], {100, 500}],
Dynamic@PieChart[data, ImageSize -> size]}]]
and
lst = #/(Plus @@ #) & /@ Table[Random[], {5}, {3}];
Do[
data = lst[[i]]; Pause[1], {i, 1, 3}]
Regards
Jens
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.
>
> Many thanks!
>
> Jason
>
>
> --
> Dr J. McKenzie Alexander
> Department of Philosophy, Logic and Scientific Method
> London School of Economics and Political Science
> Houghton Street, London WC2A 2AE
>
>
>
>
> Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
>