2
$\begingroup$

I have the following code:

size = 10;
g = GridGraph[{size, size}];

getEdges[w_] := #[[1]] -> #[[2]] & /@ Partition[w, 2, 1];
getPath[v_] := 
  getEdges[Join @@ FindShortestPath@g @@@ Partition[v, 2, 1]];

Iterate[s_, t_, 0] := getPath[{s, t}]
Iterate[s_, t_, n_] := Iterate[s, t, 0]

graphArrow[edge_] := 
 Arrow[{GraphEmbedding[g][[edge[[1]]]], 
   GraphEmbedding[g][[edge[[2]]]]}]

M = Manipulate[
  HighlightGraph[g, {Style[Source, Blue], Style[Destination, Red]}, 
   VertexSize -> Medium, 
   Epilog -> {Black, Arrowheads[.03], 
     graphArrow /@ Iterate[Source,  Destination, n]}],
  {n, 0, 100, 1}, {Source, 1, 100, 1}, {Destination, 1, 100, 1}]

CloudDeploy[M]

When attempting to use CloudDeploy on M I get a Manipulate expression with "code" inside of it, as follows: enter image description here

How can I fix this?

$\endgroup$
  • $\begingroup$ The Cloud has worked for me using FormFunction instead of Manipulate, and making sure that the graphs are uploaded with CloudExport, if they are fixed, or generated as animated GIF with the last argument of FormFunction, if they have to depend on the final-user answers $\endgroup$ – MaTECmatica May 13 '17 at 21:02
1
$\begingroup$

Here is a version using FormFunction[] instead of Manipulate[]. It is not perfect (the numbers are not shown in the output) but I guess is a good starting point

ff1 = FormFunction[
   {{"n", "Value of n:"} -> "Integer",
    {"Source", "Source id:"} -> "Integer",
    {"Destination", "Destination id:"} -> "Integer"
    }, 
   Function[
    size = 10;
    g = GridGraph[{size, size}];
    getEdges[w_] := (#[[1]] -> #[[2]] &) /@ Partition[w, 2, 1];
    getPath[v_] := 
     getEdges[Join @@ FindShortestPath@g @@@ Partition[v, 2, 1]];
    Iterate[s_, t_, 0] := getPath[{s, t}];
    Iterate[s_, t_, n_] := Iterate[s, t, 0];
    graphArrow[edge_] := 
     Arrow[{GraphEmbedding[g][[edge[[1]]]], 
       GraphEmbedding[g][[edge[[2]]]]}];
    HighlightGraph[
     g, {Style[#Source, Blue], Style[#Destination, Red]}, 
     VertexSize -> Medium, 
     Epilog -> {Black, Arrowheads[.03], 
       graphArrow /@ Iterate[#Source, #Destination, #n]}]
    ],
   "GIF",
   AppearanceRules -> 
    <|"Title" -> 
      "https://mathematica.stackexchange.com/questions/145963", 
     "Description" -> "José Luis Gómez-Muñoz"|>
   ];
CloudDeploy[ff1, Permissions -> "Public"]

Here is the link: https://www.wolframcloud.com/objects/a3158299-9111-42ba-af80-83646f6f522b Hope that helps

$\endgroup$
  • $\begingroup$ Thanks! It works well, though I am disappointed CloudDeploy seems to be bugged $\endgroup$ – mich May 14 '17 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.