2

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?

aellab
  • 185
  • 4
  • 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 – MaTECmatica May 13 '17 at 21:02

2 Answers2

1

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

MaTECmatica
  • 588
  • 4
  • 12
1

Just add SaveDefinitions->True in your manipulate function and it should work. The reason your version doesn't work is because the definition for "g" is not carried over to the clouddeploy"ed" object. Here is the version that worked for me:

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}, 
  SaveDefinitions -> True]
CloudDeploy[M] 
```