Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.3K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Beginner using CloudDeploy[FormFunction[]]

Posted 11 years ago

Hello!

I am a math teacher. Below is my code to just output a graph of any function. Unfortunately, it is only outputting a blank Cartesian grid. Any help would be sincerely appreciated. Thank you all!

CloudDeploy[FormFunction[{"equation" -> "MathExpression"}, Plot[ #equation, {x, -10, 10}]&, "PNG" ]]

PS. I halfway blindly copied this, and have no idea what the & does; just that it breaks without it.

POSTED BY: Uzair Qarni
5 Replies
POSTED BY: Sean Clarke
Posted 11 years ago
POSTED BY: Uzair Qarni

Restricted depends heavily on the type (its first argument). The documentation for Restricted doesn't cover its full behavior, just a very large set of common ways that it is used.

Look at the documentation for things like "Expression" and "MathExpression" under "Restriction Specifications". These documentation pages cover how Restricted is used with them.

http://reference.wolfram.com/language/ref/interpreter/Expression.html

The documentation pages for Interpreter types also have examples of how Restricted is used with them.

POSTED BY: Sean Clarke

The issue is somewhat complicated.

If Plot is given something that isn't the correct form, it makes a blank plot.

The rest is somewhat difficult to explain without more experience. Your code above doesn't put variables into a proper context. Contexts are much like namespaces in other languages. In the example below, I have "MathExpresion" put all the variables into a context called "LocalContext" and then use that context in your code:

CloudDeploy[
 FormFunction[{"equation" -> Restricted["MathExpression", Automatic, Automatic, "LocalContent`"]}, 
             Plot[#equation, {LocalContent`x, -10, 10}] &, 
             "PNG"]
]

The & operator defines something called a pure or anonymous function.

Is there somewhere you copied this code from? I'd like to check that it explains some of this if possible.

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