Developer Guidelines for Mathematica Player and Player Pro Compatibility
Technical Summary
The Mathematica Player family of products provides deployment engines for Mathematica applications via graphical user interfaces using the dynamic interface features introduced in Mathematica 6.
Central to deploying your applications is ensuring that they are entirely controllable via GUI elements such as sliders, checkboxes, popup menus, locators, and input fields. Note that Mathematica's "line-in, line-out" model invoked with Shift+Enter or the Evaluation menu is not supported by Player.
For a summary of differences between Player, Player Pro, and Mathematica, see below or view the comparison chart.
Note that there are no special considerations when creating documents for viewing in Player or Player Pro. All notebook features can be displayed and printed from either one.
Programming for Player and Player Pro
Almost all programming and computational functions available in Mathematica can be used to build applications for Player and Player Pro. However, there are a few programming restrictions for applications deployed with Player Pro, and some additional restrictions for Player:
Player Pro and Player
- MathLink operations, including .NET/Link, are not supported. Avoid using commands such as Install, LinkConnect, LinkOpen, Links, etc. This includes links to remote Mathematica kernels such as gridMathematica.
- InputField will not accept arbitrary Mathematica programs, although it will accept mathematical expressions and any other input that does not look like a Mathematica program.
- Alternative front ends to the kernel, such as those that could be written in Java, C/C++, or .NET, are not supported. The only supported method of using a kernel is through the Mathematica notebook interface.
- GUIKit is not supported.
Player Only
- All interactive content must be generated with the Manipulate command and may only use mouse-driven elements (Slider, Locator, Checkbox, PopupMenu, etc).
- Non-numeric InputFields are not supported. Avoid InputField[x, String] and InputField[x, Boxes]. InputField[x, Expression] and InputField[x] are restricted to work only with numbers, and InputField[x, Number] works normally.
- Dialog windows are not supported. Avoid using Input or InputString.
- Data import and export are not supported from within Player except for Wolfram-curated data sources (e.g. ChemicalData, CountryData, WordData). Note that data can be preloaded into your application during authoring (see below). Avoid commands such as Import, ImportString, ExportString, ReadList, OpenRead, OpenWrite, and OpenSQLConnection.
Guidance for Preloading Data
Because Player cannot load data at runtime, you must ensure that all necessary information is embedded within the interactive elements. You can take the same approach for Player Pro applications, but you can also load external data when it is needed.
There are two basic approaches to embedding:
Initialization
Small blocks of code and data can be included in the Manipulate command
using the Initialization option, e.g.:
Manipulate[myfunction[mydata,n],{n,0,1},
Initialization:>(myfunction[dat_,n_]:=...;mydata={...})];
SaveDefinitions
For larger blocks of code, packages, or larger data files, it may be more convenient to define them before creating the Manipulate, then store their state within the Manipulate using the SaveDefinitions option, e.g.:
<<MyPackage` mydata=Import[...];
Manipulate[myfunction[data,n],{n,0,1},SaveDefinitions->True];
Utilizing External Files from Player Pro
Player Pro's ability to access external files at runtime provides several benefits.
Code Organization and Protection
For larger projects, organizing code in packages (including with Wolfram Workbench) helps maintainable development. Instead of including your
code inside a Manipulate with the Initialization command, you can include a call to the packages. All packages must be encoded either by using the Encode command or by using DumpSave to create a .mx binary file.
You can then load this from your dynamic interface, e.g.:
Manipulate[myfunction[n],{n,0,1},Initialization:>Needs["EncodedPackage`"]]
A further advantage is that this encrypts your source code.
Real-Time or User-Specified Data
There are a number of ways of to incorporate external data calls in notebooks so that those with Player Pro can use their own data or get pre-specified real-time data. Typical examples:
- Initialize the application with data from a remote source:
Manipulate[...,Initialization:>(data=Import["http://server.domain.com/latestdata.dat"])]
- Capture data from a webcam:
Manipulate[...,Button["Get image", data=Import["http://server.domain.com/webcam.jpg"]
- Have the user select a local data file for analysis:
Manipulate[..., Button["Load data", mydatapath = SystemDialogInput["FileOpen"]]]
|