7
$\begingroup$

Is it possible to deploy to cloud a matrix entry form and when submit button would be clicked and then an operation using entered matrix as argument would be executed? So far I am able to deploy APIFunction[] and FormFunction[] to cloud:

    CloudDeploy[APIFunction[{"x" -> "Number"}, #x^2 &], Permissions -> "Public"]
    CloudDeploy[FormFunction[{"name" -> "String", "age" -> "Integer"}, 1]]

, but is there a way I could get similar results to FormFunction[], but instead of form, have a matrix input?

$\endgroup$

1 Answer 1

8
$\begingroup$

If by matrix input you mean a grid of input cells, then I believe you have to make it yourself. Here's an example.

(* Create a list of field names *)
fields = Flatten@Outer[
    "x" <> ToString@# <> ToString@#2 -> "Number" &,
    {1, 2, 3, 4, 5},
    {1, 2, 3}
    ];
fieldNames = First /@ fields;

(* Take a FormObject and create a grid of with the inputs *)
layout[form_] := Grid@Map[form[#, "Control"] &, Partition[fieldNames, 3], {2}]

(* Output function *)
dispMatrix[names_][assoc_] := MatrixForm@Partition[assoc /@ names, 3]

(* Deploy it! *)
CloudDeploy@FormFunction[
  fields,
  dispMatrix[fieldNames],
  "PNG",
  FormLayoutFunction -> layout
  ]

How it looks:

form example

$\endgroup$
3
  • $\begingroup$ Oh my God, that is incredibly useful. Thank you! $\endgroup$ Commented May 29, 2015 at 22:55
  • $\begingroup$ Pickett, If I want to do some calculations over the form fields. How to access those? $\endgroup$
    – Vijay
    Commented Feb 19, 2016 at 7:22
  • $\begingroup$ @Vijay You implement your own dispMatrix function that generates whatever result you want to return. $\endgroup$
    – C. E.
    Commented Feb 19, 2016 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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