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 ...


14

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_, ...


12

Just like Albert I recommend using the second argument of Dynamic. Furthermore I recommend that you embrace the first A in AJAX, which stands for "asynchronous", so the kernel isn't busy while it collects the data (this might be why some change events are lost with your code). You can see how well the second argument of Dynamic works with this example: ...


12

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 ...


12

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


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

I believe you want "FrontFaceColor" which can be found as a specification in this list: Graphics[{FaceForm[RGBColor[2/3, 1/3, 2/3]], EdgeForm[Black], Dynamic[{If[CurrentValue["MouseOver"], Darker @ CurrentValue["FrontFaceColor"]], Disk[]}]}] You may also find "FrontFaceOpacity" of use. Simply guessing I found that "BackFaceColor" is also ...


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[ ...


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 @ #, ...


9

There are some doubts about using SaveDefinitions (1), (2), so let's implement a brute force approach which may be later used automaticaly. Scheme Needs @ yourPackage (*a*) CDFDeploy[...]& @ With[{ source = (text content of the package, encoded or whatever) (*b*) }, DynamicModule[{ ... }, ... , Initialization:>( Get[#]& @ ...


9

I think you are actually not doing anything wrong but have found one of those cases where the automatic dependency tracking doesn't work (I think this is a bug). You can make the code work (version 10.1 on Windows) by explicitly telling the last Dynamic to track choices: Dynamic[choices,TrackedSymbols:>{choices}] There are some things in your code ...


9

I think the standard way to do this is to use the second argument of Dynamic, e.g. like so: With[{ getCompletion = Function[ Import[ "https://maps.googleapis.com/maps/api/geocode/json", "JSON", "RequestParameters" -> {"address" -> #} ] //. {{r__Rule} :> (Association[r])} ]}, DynamicModule[{ addr = "555 Mission St, San ...


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

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 = ...


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]}, ...


8

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}, ...


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 ...


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[], ...


7

With the arbitrary datasets datasets = {dataset1, dataset2, dataset3} = RandomReal[#, 100] & /@ {1, 2, 3}; one can pre-render the plots and add an empty plot for the case when no dataset is selected plots = Append[ MapThread[ListPlot[#1, Joined -> True, PlotStyle -> #2] &, {datasets, ColorData[97] /@ Range[3]}], ...


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"], ...


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]}]


7

This implements the rotation part. Still pondering which is the better way to implement the interface for multiple transformations: perComponentTransform[img_Image] := Module[{mc, m, col, colRuls, centerRuls, maskDataRuls, mask}, mc = MorphologicalComponents[img]; m = Max@mc; col = Colorize[mc, ColorFunction -> "Rainbow"]; colRuls = ...



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