3
$\begingroup$

I wish to display multiple lines of text as output from CloudDeploy FormFunction.

I have tried using a string containing \n with no luck. Using Column works to some degree but I cannot create empty lines and cannot left align the text. It is always centered.

CloudDeploy[
    FormFunction[
        {"x" -> "String", "y" -> "String"}, 
        Column[{#x, "",#y}] &
    ]
]

I have tried using the solution from FilePrint doesn't print file when running on Wolfram Programming Cloud

However this did not work(no line breaks in output)

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 May 18 '16 at 18:03
3
$\begingroup$

Yes, it seems Column and Row are still broken (How to add a Style string or Hyperlink in CloudDeploy?). Let's use Spacer to create space.

Also Grid seems to respect Alignment option:

CloudDeploy[
   FormFunction[
      {"x" -> "String", "y" -> "String"}, 
      Grid[List /@ {#x, Spacer[1], #y, #y, #y}, Alignment -> Left] &
   ]
]

enter image description here

$\endgroup$
4
$\begingroup$

In general you can exert quite a bit of control over the results by using an XMLTemplate. For example:

hoverGrid=
"<!DOCTYPE html>
 <html>
  <head>
   <style>
    table {
      width:100%;
    }

    th, td {
      padding: 8px;
      border: 1px solid black;
      text-align: right;
    }

    tr:hover{background-color:lavender}
   </style>
  </head>
  <body>
   <* Column[{#x,#y}] *>
  </body>
 </html>";

It's worthwhile to check TemplateExpression (which appears in the template as <*expr*>). If you need more spacings, use the CSS styling to do so (probably padding).

CloudDeploy[
 FormFunction[{"x" -> "String", "y" -> "String"}, 
  XMLTemplate[hoverGrid][##] &, "HTML"], "testLines", 
 Permissions -> "Public"]

here is the result:

Mathematica graphics

$\endgroup$
2
$\begingroup$

To display multiple lines in a browser insert a <br> tag between each line:

CloudDeploy[
   FormFunction[{"x" -> "String", "y" -> "String"}, #x <> "<br>" <> #y & ], 
   FileNameJoin[{$CloudRootDirectory, "TwoLineTextOutput"}]]
$\endgroup$

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.