Updated: presentations are now available from the Wolfram CDF Virtual Workshop.
General info on the CDF format/creation/deployment:
1. Manipulate or DynamicModule?
Though it is often stated that the interactive content in a CDF must be Manipulate
-based, or must be generated with the Manipulate
command, this is not necessarily true. Thus one can create a DynamicModule
object:
In[1] := func[x_] := 123;
In[2] := DynamicModule[{x = 0}, Panel[Column@{InputField[Dynamic@x, Number], Dynamic@func@x}]]

but when the output cell is deployed, and the created CDF file is opened (in Mathematica or with the plugin in the browser), the result is this:

Apparently, the DynamicModule
is accepted by the CDF-deployer, but the external function is not recognized. This, according to Sjoerd's answer, can be solved by wrapping the internals (or the whole) of DynamicModule
in Manipulate
. Manipulate
, however, does not solve everything, see next section.
To conclude, it is definitely not true that only Manipulate
objects can be used in a deployed cdf. Looking at the source code of the examples of the CDF Info Kit, one can realize that rather complex dynamic interfeces can be constructed within the boundaries of the cdf-restrictions, that can be opened as fully functional documents with the Player.
It was explicitly stated by Yu-Sung Chang (CDF Workshop 2012) that Manipulate
, Dynamic
and DynamicModule
are allowed to be the backbone of a CDF. The major benefit of using Manipulate instead of DynamicModule is described next, and in Albert's answer.
2. Save definitions
First, there is no need to put every function that is external to the Manipulate
/DynamicModule
/Dynamic
output into the Manipulate
/... body. If they are in the same notebook when the output panel is deployed, and SaveDefinitions->True
is used, they are saved with the output correctly.
This works for even packaged function, while we are using full CDFs (i.e. non-free CDFs, to open with Mathematica or Player Pro), as this video demonstrates it.
The problem happens when one wants to deploy for the web or for the CDF Player. The following example demonstrates, that SaveDefinitions
does not grab all the definitions from the packages:
func[x_] := 123;
DynamicModule[{x = 0},
Manipulate[
Column@{Dynamic@func@x, myPackage`myFunc@"test"},
{dummy, None},
Initialization :> (Needs@"myPackage`"),
SaveDefinitions -> True]
]
where myPackage`
is a custom package. When the above code is deployed for the browser plugin, the result is this:

Thus func
is saved but not the packaged function myFunc
. The same thing happens if I remove the DynamicModule
wrapper, or move the Manipulate
to be the outer wrapper. It very much seems so that the free CDF version, deployed for the browser plugin or CDF Player, is not able to handle packaged functions, only the full CDF version, intended to open with Mathematica or with Player Pro.
One important point to mention here is the difference of the evaluation sequence of CDFs. While a normal notebook's evaluation sequence follows cell order, loading initialization cells before anything else, this is not the case for CDFs! Dynamic CDF content is evaluated when it is first displayed on screen (i.e. in order of display), in a preemptive method. Input cells, including initialization cells, will not be evaluated! "There is no guarantee that cells will be evaluated in order." (Yu-Sung Chang). It is wrong to assume that a following cell relying on the evaluation of a previous cell will be evaluated correctly, as their order of evaluation is not determined by cell order.
This prompts that all content for a CDF (if it is outside of the Manipulate
/DynamicModule
) should be in the same dynamic cell, where the actual dynamic content resides, to make sure they got evaluated together. Since no order of evaluation can be guaranteed, a Dynamic cell should not depend on any other cell! So instead of deploying
p = 10;
Dynamic[p]
where p = 10
won't be saved with the deployed dynamic output cell, use instead:
Dynamic[p, Initialization :> (p = 10)]
which explicitly saves the value of p
with the dynamic cell. Another way to ensure evaluation is to use SaveDefinitions -> True
, if one uses Manipulate
.
Also, it is stated here by the User Interface Group at WRI:
"SaveDefinitions
can also be used for function definitions, although
it doesn't always reach into packages correctly. Nonetheless, it
often works well, and is used in Demonstrations by default."
meaning that it works well with standard packages, but not with user packages.
So SaveDefinitions
does not grab the packaged function for the free player, it only gets definitions correctly with Player Pro (or Mathematica). One solution is to use DynamicModule[{(* local variables *)}, (* dynamic content *), Initialization :> (* my code *)]
putting everyting under Initialization
, and live with the fact that a security warning will appear when deployed. An other hacky method exists though (Yu-Sung's trick), that can be used to load user packages in CDFs, during runtime, via ImportString
:
data = ImportString["myPackage.m", "Text"];
Manipulate[
(* dynamic content *),
{a, None},
Initialization :> (ImportString[a, "NB"])
]
3. Deploying the output only vs. the whole document
...
4. Differences between Mathematica Player, the browser plugin, and Mathematica Player Pro
Basically, there are two Players and two types of CDF files (as Albert has pointed out as well). The players are: the free CDF Player and the non-free Player Pro. The formats are: free CDF and licenced CDF.
Any of Mathematica, CDF Player or Player Pro installs the web plugin as well:
"The free player installs the browser plug-in, as do all Mathematica-based products. The plug-in tends to be the lowest common denominator wrt to feature support."
(by André Kuzniarek, CDF Workshop 2012). These plugins can also be installed from the Mathematica preferences page or during installation. Also, the plugin is different from all other applications (CDF Player, Player Pro, Mathematica), as for it the strictest security concerns apply, and therefore it is sandboxed. It provides the most restricted (though most secure) environment. The browser plugin (at the moment) is not available under Linux.
Following detailes gathered mostly from here:
Mathematica Player (or CDF Player)
- Released just after V6 (pre V6 there was MathReader, a free static notebook viewer with no interactive elements and no evaluation capability)
- Static notebook viewer
- Free desktop runtime for viewing
Manipulate
-based interactive content (and supported the launch of the Demonstrations site) (note that it is not necessary to use Manipulate
as the base, see above sections)
- Required uploading of notebooks to Demonstrations site to be "playable"
- The CDF Player also installs a web plug-in:
- Full-screen mode
- Embeddable objects (as seen on the Demonstrations site)
- concerning licensing:
- Terms spelled out on website
- CDF usage is tied to Player licensing
- Free when content is free, licensing required when content is licensed
- Player displays logo in corner of embedded content, and terms language on toolbar for full page and desktop content
- Publisher level signing of CDF docs removes these "watermarks" for commercial content
Mathematica Player Pro (to open commercial/full CDFs)
- Same features as Player but allowing evaluation of inputs and higher level Mathematica functionality (data loading etc.)
- $200 app
- No need to upload notebooks, works with any notebook
- Commercial app deployment channel
5. Differences between free CDF and full CDF
I borrowed the terminology from Jens' post. Some differences are listed in the official guidelines here, indicating what you can not do in a free CDF:
- All interactive content must be generated with the
Manipulate
command
and may only use mouse-driven elements, such as Slider
, Locator
,
Checkbox
, PopupMenu
, etc.
- Dialog windows are not supported.
- MathLink operations, including J/Link and .NET/Link, are not
supported.
- Data import and export are not supported from within CDF Player with
the exception of Wolfram-curated data sources (
ChemicalData
,
CountryData
, WordData
, etc.).
More from the CDF Workshop:
Import
from public web sources is allowed
- online Wolfram curated data is available
- local file operations are prohibited
- any *Link technology is disabled
- string
InputField
is not allowed
- notebook related operations are not allowed
- no webcam (though there is a debate ATM, so it could change in the future)
- no parallel computation
- no GPU access
- no 3D hardware antialiasing
Though there are methods to partially overcome some of these. Some other restrictions I figured out:
- Free CDF does not work with
Initialization :> Needs["MyPackage`"]
calls.
- Mostly all complex functions (more complex than
f[x_] := x + 2
) cause some kind of security issues causing the disabling of dynamic updating, see next section.
6. Security issues
The followings are small detailes gathered from the CDF Workshop. The security issue rises when a function is involved in the dynamic output:
- with definitions
- that changes attributes
- with options
- package related functions
ToExpression
/MakeExpression
Compress
/Uncompress
These are only issues in the CDF Player or in the browser plugin, as they have more strict restrictions on security. This kind of security issue is due to the fact that the location where the CDF lives, is not part of a default trusted path. John McLoone stated in the CDF Workshop that this issue wouldn't be an issue at all on a server, where the CDF would be opened from a safe location on the server, under the browser. He also stated that it is in development (or planned) to set up a trusting mechanism, where the user can set trusted paths and authors.
ReadProtected
? $\endgroup$Protected
, nothing extra. $\endgroup$Manipulate
is the outer mostHead
. I have done this before with a complex nestedTabView
that called functions. I wrappedManipulate
around it withSaveDefinitions -> True
and ran it in fullscreen mode and it worked on a web page. $\endgroup$