# How to eliminate error message from a LocatorPane showing graphincs?

My code

q1 = {{1, 0.5}, {2, 0.5}}; q2 = 10; q3 = {3, 3};
Dynamic[
LocatorPane[Dynamic[q1],
Graphics[{},
PlotRange -> {{0, Dynamic[q2]}, {-1, 1}},
Axes -> True],
Appearance -> q3],
TrackedSymbols :> {q3}]


is wrong, because when I press this button

Button["Add", AppendTo[q1, {q1[[-1, 1]] + 1, 0.5}]; AppendTo[q3, 1]]


a bad output cell appears, and I get the mesage

The specified setting for the option GraphicsBoxOptions, PloRange cannot be used."

What is wrong here??

-
I don't know but if you leave q2 without Dynamic it will work, also wrapping LocatorPane and Button with e.g. Column will prevent the error too. –  Kuba Dec 29 '13 at 21:21
as Kuba said, the problem is that you wrapped q2 in Dynamics. Dynamics is for display only. Nothing that has Dynamics will be understood by the Kernel. only the FE understands dynamics. So passing a Dynamics to PlotRange is not going to work. Dynamics should be an outermost wrapper, something that can be only handled by the FE' and not send to the kernel. –  Nasser Dec 29 '13 at 23:13
From what i read about Dynamic[], I should nest them to avoid the whole LocatorPane[...] expression to be reevaluated whenever q2 changes (why would that be necessary?). Not true? –  Coolwater Dec 30 '13 at 12:05

I believe what you want is this:

q1 = {{1, 0.5}, {2, 0.5}}; q2 = 10; q3 = {3, 3};
Dynamic[LocatorPane[Dynamic[q1],
Graphics[{}, PlotRange -> Dynamic@{{0, q2}, {-1, 1}}, Axes -> True],
Appearance -> q3], TrackedSymbols :> {q3}]


You can have a dynamic PlotRange, but you have to wrap the whole range specification with Dynamic.

-
I think there is still something missing. Try {Dynamic[LocatorPane...] , Button[...]} and later Column@{Dynamic[LocatorPane[...]], Button[...]}, with PlotRange->{{0, Dynamic@q2},{...}} –  Kuba Dec 30 '13 at 7:00
Something is missing? Would you please clarify, because the code seems perfectly fine to me. –  Coolwater Dec 30 '13 at 12:11
I tried Dynamic[Print[0];LocatorPane[(*Michael E2 answer, except for "TrackedSymbols:>{q3}"*)] and found that option to be unnecessary. –  Coolwater Dec 30 '13 at 12:22
@Coolwater I meant, it works but I don't understand something with the behaviour of FE here. :) This answer works ok. –  Kuba Dec 30 '13 at 18:04

This is an extended comment, not an answer.

Kuba and Nasser have already explained why your code doesn't work, but looking at you code suggests to me that you also want all your locators to have a y coordinate of 0.5, so you might consider this variant of your code.

Dynamic[
LocatorPane[
Dynamic[q1],
Graphics[{}, PlotRange -> {{0, q2}, {-1, 1}}, Axes -> True],
{{0, .5}, {q2, .5}},
Appearance -> q3]]


I have added a third argument to LocatorPanel` which will constrain the locators' y-coordinate to 0.5.

-