Hot answers tagged

20

Presumably your Notebooks are not being saved in a Trusted Path. Start by reading the tutorial Notebook Security, and note: If the notebook's directory is trusted, the notebook will be allowed to automatically perform dynamic evaluations without alerting the user. If the notebook's directory is untrusted, the user will be alerted upon any attempt by the ...


16

Here is a slight modernization of old code by Stan Wagon for generating epicycles, based on this paper by Frank Farris: Options[EpicyclePlot] = {AnimationRunning -> True, ColorFunction -> Automatic, "Frames" -> 16, "Movie" -> True, "MovieTimeInterval" -> Automatic, PlotPoints -> 100, "ShowWheels" -> True}; EpicyclePlot[{radii_, ...


14

The basic idea is fairly simple: GraphicsComplex[ ReIm@Accumulate[epicycle @@ data], {Point@Range[n + 1], Line@Range[n + 1], MapThread[Circle, {Range[n], data[[1]]}] }] In the above epicycle computes each epicycle, in essentially the same way as ubpdqn as complex numbers, which are then added together with Accumulate; ReIm converts the complex ...


13

There is a built-in DateSetter: {Developer`DateSetter[Dynamic@date], Dynamic@date} By default the first selectable date is tomorrow and one can only go to future months. However, the option NotebookTools`DateSetterRange can be used to set the first selectable date to sometime in the past, {Developer`DateSetter[Dynamic@date, NotebookTools`...


12

This should work: SetSystemOptions["TypesetOptions" -> "ColorDirectiveSwatches" -> False]


12

I would suggest using the second argument of Dynamic: DynamicModule[{shape = Disk[], targets = RandomPoint[Disk[], 10]}, Panel@Column@{ Item[ RadioButtonBar[Dynamic[ shape, (targets = RandomPoint[#, 10]; shape = #) & ], {Disk[] -> "Disk", Rectangle[] -> "Rectangle"}], Alignment -> Center ], Dynamic@...


11

I really think that other answers here are adequate, but since specific examples are being requested, here's one. f[x_] := memoize[x] memoize[x_]:=memoize[x]=x This is a function you want to call inside and outside of Dynamic. You want the caching effect, but you don't want Dynamic to go crazy on this. Which it will. Observe: In[139]:= Clear[memoize]; ...


11

Update Inspired by @Craig, @MichaelE2 and @J.M. and integrating varying aspects (but without the polish of all the options): ep[{r_, a_, o_}, n_] := Module[{fun = Function[x, Accumulate@ Prepend[ReIm@MapThread[#1 Exp[I #2 x + I #3] &, {r, a, o}], {0, 0}]], col = RandomColor[Length@r], smin = Max[2 Pi/a], tab, g}, tab = ...


11

Again I choose a dynamic module to implement your request. This time I don't use a locator, but take direct control of mouse events. With[{span = 10., viscosity = .01}, Framed @ DynamicModule[{mouseXY, xmin, xmax, ymin, ymax}, {xmin, xmax} = {ymin, ymax} = span {-1., 1.}/2.; EventHandler[ Dynamic @ Plot[span Sin[t]/2., {...


11

This is a direct copy-paste of @m_godberg's code, with a few minor changes to get rid of the viscosity parameter and allow the graphics to move precisely as much as the mouse was dragged. With[{span = 10.}, Framed @ DynamicModule[{mouseXY, xmin, xmax, ymin, ymax}, {xmin, xmax} = {ymin, ymax} = span {-1., 1.}/2.; EventHandler[ ...


11

To understand this, look at the typesetting: In[1]:= ToBoxes[Button["Print", Dynamic[a++]]] // InputForm Out[1]//InputForm= ButtonBox["\"Print\"", ButtonFunction :> Dynamic[a++], Appearance -> Automatic, Evaluator -> Automatic, Method -> "Preemptive"] Front end options, which includes all box options, can take Dynamic heads. That basically ...


11

This answer builds on @AlbertRetey's answer where, in the comments, you wanted some guidance as to how Wolfram creates robust controls. Think very carefully about the division of labor between the FE and the kernel. You've effectively embedded the entire implementation inside the FE by putting the update functions in DynamicModules. Generally, this is a ...


10

Reanalysis My earlier assertions were incorrect or at least incomplete. I now believe the problem in your code originates because of a particular behavior that can be seen in this separate example: asc = <|foo -> <|bar -> <|baz -> 1|>|>|> <|foo -> <|bar -> <|baz -> 1|>|>|> asc[foo][bar][baz] = 2; ...


10

Quick fix is to use e.g. Inactivate and friends: Manipulate[ Column[{ Activate @ #, Panel @ ExpressionCell[ # /. Inactive -> Defer, "Notebook", "Input" ] }] & @ Inactivate @ Plot[Sin[x], {x, -3, 3}, AxesLabel -> {xlabel, ylabel}, Ticks -> {tics, tics}] , Control[{{tics, Automatic, ""}, {Automatic -&...


10

Whole ListPlot is recalculated at each click because clicks value has changed, you can isolate Dynamic parts of graphics in Epilog to avoid that. Using EventHandlers there will allow you to drop clicked points. testdata = Array[{#, 1 + #^2*RandomReal[]} &, 100]; clicks = {testdata[[1]], testdata[[-1]]}; ListPlot[ Button[Tooltip @ #, AppendTo[...


10

You are almost there but Graphs are not mutable so: DynamicModule[{graph}, Dynamic[graph] , Initialization :> ( graph = Graph[ {1 -> 3, 2 -> 3, 3 -> 6, 4 -> 6, 1 -> 5, 5 -> 4, 6 -> 2}, VertexLabels -> "Name", VertexShapeFunction -> ( EventHandler[ Disk[#1, .1], "MouseClicked" :> (graph = ...


9

I recently needed to do something like this. Here's a simplified version of what I came up with: DynamicModule[{elem = "Hydrogen"}, Panel[Row[{(ColorData["Atoms", "Panel"] /. HoldPattern["MouseClicked" :> rhs_] :> ("MouseClicked" :> (elem = CanonicalName[ElementData[Cases[Unevaluated[rhs], _Rule, ∞][[1, ...


9

No, you only need the Internet connection if you are using Wolfram|Alpha to enter your inputs, because this is a web service. If you had typed the Mathematica input Plot[Sin[x]/x, {x, -9.4, 9.4}] rather than graph of sin[x]/x then this would not have happened. W|A's interpretation of inputs is unpredictable at the best of times, so I would suggest ...


9

This is more like Dynamic: Clear[f] SetAttributes[f, HoldFirst] (*f[x_]:=g[x]*) Table[f[i], {i, 5}] (* {f[i], f[i], f[i], f[i], f[i]} *) By giving f a definition, it evaluated while in Table, during which the i got evaluated.


9

This isn't a very elegant implementation, but since nobody else has answered so far, I've decided to post it. It is an extension of what I posted in this previous question. f1[x_] := x^2 f2[x_] := x + 1 With[{span = 10., δ = .1, f1DragPt = {0., f1[0.]}, f2DragPt = {0., f2[0.]}}, Framed @ DynamicModule[{mXY, action, xmin, xmax, ymin, ymax, p1, p2}, ...


9

This is probably not really an answer but definitely too long for a comment. First thing that seems worth mentioning is that the following part of the documentation for InheritScope can be interpreted as if the behavior you see is an intended feature: With the setting InheritScope->False, a DynamicModule will continue to inherit variable settings from a ...


8

Random test function I'm assuming all the functions to be considered are nonnegative, just as in the example. SeedRandom[0]; data = Transpose[{ Range[0., 1., 1./40], FoldList[ Max[0., Min[##]] &, Reverse@Sort@RandomReal[{-0.65, 1}, {41}] ] }]; f = Interpolation[data, InterpolationOrder -> 1]; Plot[f[x], {x, 0, 1}] ...


8

As a Palette 1) Using ListLinePlot: CreatePalette[{ DynamicModule[{miu, timeStep = 0.1}, Grid[{ {Row[{"Current MemoryInUse [MiB]: ", Dynamic[Style[miu[[-1]], Bold], TrackedSymbols :> {miu}]}], Item[Row[{"time step: ", RadioButtonBar[Dynamic[timeStep], {0.1, 0.5, 1}], Spacer[35]}], Alignment -> Right]}, {Dynamic[...


8

How can I constrain the locator to stay within the region defined by RegionPlot? You can check if locator's coordinates fulfill the condition defining your region. It can be done with the second argument of Dynamic if you introduce Locator explicitly. Take a look at line with Locator[Dynamic[p, With[{... A strange behavior occurs whenever the left ...


8

I think this may be the behavior you desire. I am borrowing Kuba's modified ClipPanes specification. One should not need RawBoxes here I think but it does serve the purpose to get our Dynamic expression into the Front End box form. DynamicModule[{vp}, {vp} = Options[Graphics3D, ViewPoint][[All, 2]]; Graphics3D[{FaceForm[Red, Blue], Sphere[]}, Axes ...


7

I think when it's done each time you save the notebook it should be nice enough :) SetOptions[ EvaluationNotebook[], NotebookEventActions -> { {"MenuCommand", "Save"} :> (Scan[ Module[{nr}, SelectionMove[#, All, CellGroup, AutoScroll -> False]; nr = Length @ Select[ SelectedCells[], Experimental`...


7

An adaption of this answer for an ActionMenu and to your styling: assnMenuK[slowF_, a_Association, title_: "Choose"] := DynamicModule[{done = False, lastSelection = ""}, Grid[{{ ActionMenu[title, KeyValueMap[#2 :> (lastSelection = #2; done = "working"; slowF[#1]; done = True) &, a], Method -> "Queued"], Dynamic@Style[...


7

A simple example of one popup depending on the selection of another: DynamicModule[{x, y, list}, {PopupMenu[ Dynamic[x, (x = #; list = Switch[#, "A", {1, 2, 3}, "B", {4, 5, 6}, "C", {7, 8, 9}]; y = First[list]) &], {"A", "B", "C"}], Dynamic[PopupMenu[Dynamic[y], list], TrackedSymbols :> {list}]} ]


7

Here's beta version, basic functionality is delivered. I have to polish it but probably I won't have time for that this year. It has to be packed into self contained module and styling options have to be enabled. I will update a nice description of an approach too, but meanwhile, if anything is not clear, feel free to ask. ActionNestedMenu[ "Test menu" -&...


7

You can use Clock as a dynamic variable that corresponds to the time elapsed since the start of the evaluation. Dynamic@Plot[Sin[x], {x, 0, Clock[Infinity]}]



Only top voted, non community-wiki answers of a minimum length are eligible