Message Boards Message Boards

GIF and animated GIF as outputs of CloudDeployed FormFunction

Posted 7 years ago

There are some interesting advantages of using "GIF" as the format for the output of a cloud-deployed FormFunction. First a problem: the output of next code is suposed to be a Grid with pink and yellow bakcground, however when deployed in the cloud, the colors are not shown in the result:

fofu=FormFunction[{
{"n","An integer between 5 and 20:"} -> Restricted["Integer",{5,20}]},
Function[
  Grid[
    Prepend[Table[{k,Prime[k]},{k,1,#n}],{"Index","Prime"}],
    Dividers->All,Background->{None,{{Pink,Yellow}}}]
    ],
    AppearanceRules -> <|"Title" -> "Some prime numbers", 
    "ItemLayout" -> "Vertical"|>
    ];
CloudDeploy[fofu,Permissions->"Public"]

See the result here http://tinyurl.com/community20170530a. Now there is an easy fix if you want to see the pink and yellow bakcground: Use the third argument of FormFunction to specify that the output must be a GIF file:

fofu = FormFunction[{
    {"n", "An integer between 5 and 20:"} -> Restricted["Integer", {5, 20}]},
   Function[
    Grid[
     Prepend[Table[{k, Prime[k]}, {k, 1, #n}], {"Index", "Prime"}],
     Dividers -> All, Background -> {None, {{Pink, Yellow}}}
     ]
    ], "GIF", 
    AppearanceRules -> <|"Title" -> "Some prime numbers", 
    "ItemLayout" -> "Vertical"|>
   ];
CloudDeploy[fofu, Permissions -> "Public"]

See the result, with colors in the output, here http://tinyurl.com/community20170530b. You can also produce an animated GIF as the result of a cloud-deployed FormFunction, although it can take several seconds to obtain the final result, for example:

fofu = FormFunction[{
    {"f", "Function:"} -> <|"Interpreter" -> "Expression", 
      "Input" -> Sqrt[z]|>
    },
   ExportForm[Function[
       Table[
        With[{t = 1/2 (1 - Cos[\[Pi] s])},
         ParametricPlot[{(1 - t) x + t*Re[#f], (1 - t) y + 
             t*Im[#f]} /. z -> (x + I y), {x, -2, 2}, {y, -2, 2}, 
          MeshStyle -> {Directive[Thick, Darker[Red]], 
            Directive[Thick, Darker[Blue]]}, PlotRange -> 2, 
          Mesh -> Automatic]
         ],
        {s, 0, 1, 0.02}]
       ][#], "GIF", "AnimationRepetitions" -> Infinity] &,
   AppearanceRules -> 
    <|"Title" -> "Animación de funciones de variable compleja", 
     "ItemLayout" -> "Vertical"|>
   ];
CloudDeploy[fofu, Permissions -> "Public"]

See the result here (it can take several seconds to generate the output, which is an animated GIF): http://tinyurl.com/ruben20170530b

Hope that helps.

Jose from Mexico

Attachments:
POSTED BY: Jose Gomez

Thanks for posting this.

A lot of these formatting functions (like Grid, Row, Column, etc) are very old and were made well before anyone saw that they would need to be exportable to a webpage. We are still incrementally improving CloudDeploy's ability to handle them correctly. So hopefully in a future version they will work without needing to use ExportForm to return an Image.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract