# CloudDeploy a Manipulate with dependent functions

I don't seem to understand CloudDeploy; it seems like it deploys a function, but not its dependent expressions. How should I deploy an expression that may have dependencies previously in the notebook?

For example, I evaluated the following expression:

f=Sin[x];CloudDeploy[Manipulate[Plot[f,{x,0,t}],{t,1,15}]]


I then visited the deployed page, and got a plot with no function.

This is a simplified version; in more complex ones, such as when PlotRange depends on something previously defined, I can see error messages.

It seems that CloudDeploy's deployed object definition isn't closed over the set of definitions in effect. However, the docs (at ref/CloudDeploy.html) specify that:

CloudDeploy[expr,…] automatically deploys all definitions needed to evaluate expr, much like CloudSave.

Am I misunderstanding something here?

The quick fix is to use Manipulate's SaveDefinitions, making it responsible for storing dependencies:

f = Sin[x];
CloudDeploy[
Manipulate[Plot[f, {x, 0, t}], {t, 1, 15}, SaveDefinitions -> True]
]


I don't know if that is expected, maybe Documentation sticks to the wording precisely here. So it happens because f is not needed to evaluate Manipulate (it is needed to display it):

InputForm @ Manipulate[Plot[f, {x, 0, t}], {t, 1, 15}]


in contrary to e.g. InputForm @ Grid[f].

On the other hand it does not make much sense since CloudDeploy does not Hold its arguments which means expr is evaluated before sending, which means no additional definition will ever be needed if we stick to the wording...

So maybe it is worth reporting?

Compare also:

CloudDeploy[Delayed[f]]

CloudDeploy[Dynamic[f]]

• Thank you so much! Your suggestion worked perfectly. It's going to take a little thinking and practice to understand the difference between "needed to display" and "needed to evaluate". (In lambda calculus, the formalism I'm more used to, there's no difference.) I'll look into the Dynamic and Delayed docs to see if I can understand it better. – Piquan Sep 8 '16 at 7:45
• @Piquan I'm glad it helps. Yep, try to read more about Dynamic IntroductionToDynamic and typesetting Understanding evaluation and typesetting. And keep in mind that execution of those concepts may differ slightly in desktop and web world. – Kuba Sep 8 '16 at 7:53

Another "Wolfram approved" and working solution can be modeled from examples in the Wolfram demonstrations project like this: http://demonstrations.wolfram.com/TheVigenereCipher/. The trick is to use "Initialization" with a delayed assignment ( :> ). Also note the "sintest" URL at the end of the CloudDeploy function. It should help manage all of the CloudObject's you will likely be generating.

Try:

CloudDeploy[
Manipulate[Plot[f, {x, 0, t}], {t, 1, 15},
Initialization :> (f = Sin[x])], "sintest"]