# CDF won't work but NB works

I converted a .nb with the following content to a standalone CDF but I get an error that says: "An unknown box name (N) was sent as the BoxForm for the expression. Check the format rules for the expression.". What is causing this?

DrawOdds[outs_] := 46/outs - 1
MinImpliedOdds[bet_, pot_, remStack_, outs_] :=
Module[{immediateOdds, odds, impliedAmt, percPot, percStack},
immediateOdds = (pot + bet)/bet; odds = DrawOdds[outs];
impliedAmt = If[immediateOdds < odds, bet (odds - 1) - pot, 0];
percPot = impliedAmt/(pot + 2 bet);
percStack = impliedAmt/remStack; {impliedAmt, percPot, percStack}]
Needs["Units"]
DynamicModule[{bet = 230, pot = 380, remStack = 870, outs = 9},
Deploy[Style[
Panel[Grid[
Transpose[{{Style["bet", Red], Style["pot", Red],
Style["smallest remaining stack", Red], Style["outs", Red],
"implied amount", "% pot",
"% remaining stack"}, {InputField[Dynamic[bet], Number],
InputField[Dynamic[pot], Number],
InputField[Dynamic[remStack], Number],
InputField[Dynamic[outs], Number],
InputField[
Dynamic[MinImpliedOdds[bet, pot, remStack, outs][[1]] // N],
Enabled -> False],
InputField[
Dynamic[MinImpliedOdds[bet, pot, remStack, outs][[2]] 100 //
N], Enabled -> False],
InputField[
Dynamic[MinImpliedOdds[bet, pot, remStack, outs][[3]] 100 //
N], Enabled -> False]}}], Alignment -> Right],
ImageMargins -> 10],
DefaultOptions -> {InputField -> {ContinuousAction -> True,
FieldSize -> {{5, 30}, {1, Infinity}}}}]]]

• How can I properly format the code? When I copy paste each cell from Mathematica it displays here in a single line which is unreadable :-( – dabd Apr 26 '13 at 11:28
• I see that you use InputFields. These can't be used in CDF's. See this doc page. Specifically: "All interactive content must be generated with the Manipulate command and may only use mouse-driven elements, such as Slider, Locator, Checkbox, PopupMenu, etc." – Sjoerd C. de Vries Apr 26 '13 at 12:20
• As to editing: Copy MMA code as input text. Paste here and select code and press ctrl-k. Place returns and spaces until it looks right. Programmatically, you could try Leonid's work here. – Sjoerd C. de Vries Apr 26 '13 at 12:32
• Thanks. I see that only the Player Pro allows InputField but you have to pay for it. – dabd Apr 26 '13 at 12:35

As Sjoerd has mentioned, InputField in CDF-Player are restricted: they work, but only for input of numbers. This seems to be true for no matter whether run in the "standalone" CDF-Player or within the browser-plugin. The problem are only those InputFields that you use to show results, not the ones you use for input.

But there is another problem: you have to define all functions you are using within the Initialization. For this case, you can just use the SaveDefinitions Option, if you'd really make use of the "Units" package you'd have to write an explicit Initialization, and making use of symbols from a package has some additional issues, which you can learn to avoid e.g. here.

The following should work:

DrawOdds[outs_] := 46/outs - 1;
MinImpliedOdds[bet_, pot_, remStack_, outs_] :=
Module[{immediateOdds, odds, impliedAmt, percPot, percStack},
immediateOdds = (pot + bet)/bet; odds = DrawOdds[outs];
impliedAmt = If[immediateOdds < odds, bet (odds - 1) - pot, 0];
percPot = impliedAmt/(pot + 2 bet);
percStack = impliedAmt/remStack; {impliedAmt, percPot, percStack}];

Needs["Units"];

DynamicModule[{bet = 230, pot = 380, remStack = 870, outs = 9},
Deploy[Style[
Panel[Grid[
Transpose[{{Style["bet", Red], Style["pot", Red],
Style["smallest remaining stack", Red], Style["outs", Red],
"implied amount", "% pot",
"% remaining stack"}, {InputField[Dynamic[bet], Number],
InputField[Dynamic[pot], Number],
InputField[Dynamic[remStack], Number],
InputField[Dynamic[outs], Number],
Dynamic[MinImpliedOdds[bet, pot, remStack, outs][[1]] // N],
Dynamic[MinImpliedOdds[bet, pot, remStack, outs][[2]] 100 //
N],
InputField[
Dynamic[MinImpliedOdds[bet, pot, remStack, outs][[3]] 100 //
N], Number, Enabled -> False]}}], Alignment -> Right],
ImageMargins -> 10],
DefaultOptions -> {InputField -> {ContinuousAction -> True,
FieldSize -> {{5, 30}, {1, Infinity}}}}]],
SaveDefinitions -> True]


Here I just left out the InputField where it doesn't work in CDF-Player. You could try to use additional functions e.g. Framed or Panel to get a "nicer" formatting of the output numbers so that they look like disabled input fields...

• The standalone works thanks for the trouble of rewriting the code. However I have the following problem: I exported the NB as a standalone CDF, then I put it in a publicly accessible dropbox link. When I embed the link in a blog post it says it can't be loaded. This procedure works for other CDFs I have made but not for this one. Do you have an idea why I can't embed this CDF in a blog post? Thanks. – dabd Apr 26 '13 at 13:36
• @dabd: hm, have you tried to export as "Web Embedable" and run it from a local html-file in your browser? I'd ensure that this works before I'd try it from a remote site. Honestly I have only tested my answer with the "Standalone" export, it could be that for the sandboxed plugin even the Number form of InputField` isn't supported. I'll try that and probably adopt my answer accordingly... – Albert Retey Apr 26 '13 at 13:56
• @dabd: just tested my code locally with the browser-plugin and it seems to work alright. I guess that there is something wrong with your setup for the embedding in the blog post and the message that the cdf couldn't be loaded also IMO rather looks like something not related to the actual content of the CDF. Maybe an issue with accessability or just a typo in the filenames/urls? – Albert Retey Apr 26 '13 at 14:04
• Hey Albert, it was my mistake I forgot to put in the dropbox Public folder :-P. Thank you very much for all the help! – dabd Apr 26 '13 at 14:06