Message Boards Message Boards


Do Dynamic locators work on the cloud?

Posted 3 years ago
6 Replies
8 Total Likes

In Stephen Wolfram's book (Elementary Introduction...) he says " a web page you'll be able to use active sliders... though they'll run slower than if they were directly on your computer" (1st ed., p.218). Fair enough, but I wonder if other objects such as dynamic locators actually work on the cloud at all. I just deployed a notebook with a dynamic locator which should move when dragged, but it simply doesn't seem to work at all. Sliders work, although somewhat slow, as expected.

6 Replies

A support for Locator on WPC is limited but exists. From my experience the only way to make it work is to use LocatorPane or to use Manipulate with its variable having Locator control type.

Also, Arrow[{{0, 0}, Dynamic@x}] won't work out of the box, you need to have whole Graphics wrapped with Dynamic, otherwise it won't update.

So while on a desktop this works:

DynamicModule[{x = {1, 1}},
 Graphics[{Gray, Arrow[{{0, 0}, Dynamic@x}], Locator@Dynamic@x}, PlotRange -> 1, Frame -> True]

it won't on a cloud and you need:

  Graphics[{Gray, Arrow[{{0, 0}, x}]}, PlotRange -> 1, Frame -> True],
  {{x, {1, 1}}, Locator}
] // CloudDeploy[#, Permissions -> "Public"] &

(*notice no Dynamic on x, instead the body of the manipulate is taking care about updates*)


   DynamicModule[{x = {1, 1}},
       Dynamic@Graphics[{Gray, Circle[], Arrow[{{0, 0}, x}]}]]
  ], Permissions -> "Public"

Thanks very much, Kuba. Both the approaches you suggest work, but the latency time is too large. For all intents and purposes, working with a dynamic locator on the cloud seems to be out of the question. The following piece of code is a small part of the kind of situation I'm dealing with, where the red vertex at the top should move smoothly as you drag it around. So far, I have changed the control to a 2D slider, which improves only slightly on the locator performance.

Manipulate[Module[{pA = {-1, 0},
pB = {1, 0}},
loc = Locator[
Dynamic[pC, (pC = {Min[Max[#[[1]], -1.5], 1], 
Min[Max[#[[2]], 0.3], 2]}) &], 
Graphics[{Red, EdgeForm[Black], Disk[{0, 0}, 0.1]}, 
ImageSize -> 10]];

Graphics[{Style[Text["A", pA, {1, 1}], 12], 
Style[Text["B", pB, {-1.5, 0}], 12], 
Style[Text["C", pC, {0, -2}], 12], {Yellow, 
Triangle[{pA, pB, pC}]},
{Thickness[0.005], Line[{pC, pA, pB, pC}]},
PlotRange -> {{-2, 2}, {-0.5, 3.0}}, 
ImageSize -> 500]], {{pC, {0.22, 1.1}}, ControlType -> None}]

The problem is that only locator is handled client side and everything is sent to the cloud for a new polygon. In general it may be possible to make simple primitives work client side but I haven't heard any news about that from WRI.

Ok, so it´s better to forget about dynamic locators on the cloud. Thanks, anyway.

Posted 2 years ago

As Kuba has discovered by trial and error, we currently only support LocatorPane in the cloud rendering. This is what Manipulate Locator control ends up using as well. We have only partial support for LocatorPane, we do not support all options, but we are improving that support within the next few releases.

In general, we do not support dynamic content within Graphics, or Graphics3D. You can however still use the approaches Kuba suggests by wrapping a dynamic around the entire Graphics expression. This will regenerate the entire Graphics expression as he mentions. Typically you want to avoid this pattern (wrapping the entire Graphics in Dynamic) in desktop for performance reasons.

Even if you use this pattern in the cloud, there is still noticeable latency as you have seen. The underlying reason for that is that we currently have to go back to the server for new graphics data. Any dynamic update requires at least one round trip back to the server in order to update your graphic. So the latency is server communication + time to generate data for your graphic the cloud understands. Unfortunately, computing this data is actually quite expensive, you can think of it roughly as Rasterize-ing your graphic every time.

We do want to push more of the graphics handling (including dynamic locators) into the client, but this is an extremely difficult thing to accomplish. It is on our longer term list of things to complete, but there is no specific timetable for it.

As Kuba also astutely points out it is feasible to support some dynamic graphics content if it is sufficiently simple. We also have some nearer-term efforts in that direction as well, but again, no specific timeline.

If this type of functionality is really key to your use case, please let us know.

Thank you, John. This functionality is not really key for my use, though it would be nice to have. I hope something will come out in the future.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract