Message Boards Message Boards

Why is CloudDeploy[] having trouble to work with Manipulate[] ?

Posted 10 years ago

I have a Manipulate[] with some initialization code (3 funcs) and 3 sliders. I have bundled all that inside a DynamicModule[] (defined as a function). So far so good, everything runs smoothly!

The problem is that I cannot deploy it to the cloud (tried different variations of CloudDeploy[]) without breaking the interface.

The funny thing is that I upload the cdf version of my code (generate it with CDFDeploy[]) to the cloud manually and it works like a charm-the problem in this case is that it is not publicly accessible and I cannot find a way to change its permissions.

Is there anyone out there with any hint on what to do? How can I make CloudDeploy[] work with DynamicModule[Manipulate[]] or how can I change the permissions of an uploaded cdf to the cloud?

Any help is HUGELY appreciated!

POSTED BY: nik tsak
10 Replies

The first thing to note is that it you don't have to include your function definitions using the Initialization option. When you CloudDeploy, any dependencies will be worked out (effectively like SaveDefinitions -> True) and saved as part of the cloud object. It is one of the nicer features of CloudDeploy that you don't have to worry about sorting out all the dependencies. That said, doing so won't fix the problem with your Manipulate. I suspect as originally written that the symbols getting created with the ToExpression call are not ending up in the same context as the symbols you are comparing to in func3 and thus preventing them from matching when compared with ===. When I tried to deploy your code as originally written, everything came out gray which seems to confirm that. The alternative code posted by Rolf Mertig above fixes this problem by using strings rather than symbols which is why his code does work. While not knowing what your full application is trying to do, I would suggest that the work done with func3 may be done more idiomatically with rules and Replace or ReplaceAll.

POSTED BY: Andrew de Laix

How can I make CloudDeploy[] work with DynamicModule[Manipulate[]]

Is there any specific reason to put Manipulate inside a DynamicModule, given that Manipulate is already a DynamicModule? What exactly the purpose of doing so? Have you tried just with Manipulate itself?

POSTED BY: Nasser M. Abbasi

I chose to enclose Manipulate[] in a DynamicModule[] because I had to hide away some intermediate definitions that are essential to the computation

You can do all that, using just Manipulate. All the demos at http://demonstrations.wolfram.com/ work with just Manipulate. Actually one of the rules, is that the first call must be Manipulate[]. So I am sure you can do what you want with just Manipulate without having to put it inside another Module. You can use the Initialization section, or use save definitions for example. But may be you have special case. Hard to know without seeing the code you have.

But when I last tried Dynamics in the cloud, when cloud was first announced, many things were not yet supported. Please see Cloud Dynamic support. Do Buttons work in the Wolfram Cloud in Manipulate?

I started making a list of things that do not work in the cloud, but got tired after a while, since the list kept growing. It might be you are using some dynamic feature/control that is not yet supported in the Wolfram Cloud. Hard to know, since there is no minimal working example given to try with. If you can make a minimal example that shows the problem, that will help.

POSTED BY: Nasser M. Abbasi
Posted 10 years ago

The following is a toy version of my actual code. Both the CDF and the notebook versions of the code run smoothly. It all goes south when it gets deployed on the cloud!

wrapper = Manipulate[

   main[s1, s2, s3],

   {{s1, 95, "Slider 1"}, 1, 99, 1},
   {{s2, 5, "Slider 2"}, 1, 99, 1},
   {{s3, 50, "Slider 3"}, 1, 99, 1},

   ControlType -> Slider,

   Initialization :> (

     func1[s1Val_: 0.95, s2Val_: 0.05] := Module[{},

       RandomReal[{0, 1}, 2]

       ];

     func2[s3Val_, s1Val_: 0.95, s2Val_: 0.05] := Module[{},

       {

        {
         {"Res1", 10^6 RandomReal[]},

         {"Res2", 10^6 RandomReal[]},

         {"Res3", 10^6 RandomReal[]},

         {"Res4", 10^6 RandomReal[]}

         },

        Table[{ToExpression[StringJoin["Res5", ToString[i]]], 
          RandomReal[]}, {i, 1, 10}],

        Table[{ToExpression[StringJoin["Res6", ToString[i]]], 
          RandomReal[]}, {i, 1, 5}],

        Table[{ToExpression[StringJoin["Res7", ToString[i]]], 
          10^6 RandomReal[]}, {i, 1, 5}]

        }

       ];

     func3[x_] := Which[

       x === Res71, RGBColor[{0., 0.4918, 0.7778}],

       x === Res72, RGBColor[{1., 0.1799, 0.1111}],

       x === Res73, RGBColor[{1., 0.2222, 0.2523}],

       x === Res74, RGBColor[{0.3011, 0.6667, 0.}],

       True, Gray

       ];

     main[s1Val_, s2Val_, s3Val_] := 
      Module[{list1, val1, array1, grid1, grid2, tmp, chart},

       list1 = func1[s1Val, s2Val];

       val1 = Rescale[s3Val, {0, 1}, list1];

       array1 = func2[val1, s1Val, s2Val];


       grid1 = 
        Grid[Prepend[
          Reverse /@ 
           MapAt[N[10^-3 Round[10^3 #/10^3]] &, 
            array1[[1]], {All, 2}], {Style[
            "some \!\(\*SuperscriptBox[\(text\), \(2\)]\)", Bold, 
            Smaller], Null}], Alignment -> Right];

       grid2 = 
        Grid[Prepend[
          array1[[4]], {Null, Style["some text", Bold, Underlined]}], 
         Alignment -> Right];


       tmp = (array1[[4]] // Reverse // Transpose);

       chart = 
        PieChart3D[tmp[[2]], ChartLabels -> tmp[[1]], 
         ChartStyle -> (func3 /@ tmp[[1]]), ImageSize -> Medium, 
         PlotLabel -> Style["some text", Larger, Bold], 
         SectorOrigin -> {Automatic, 1}];


       Column[{chart, 
         Grid[{{grid2, grid1}}, Dividers -> {{False, True}, False}], 
         Framed[Style["some text", 11, Bold, Darker[Blue]]]}, Center]

       ];

     ),

   SaveDefinitions -> True,

   SynchronousInitialization -> False,

   Deployed -> True

   ];

CDFDeploy[

 ToFileName[NotebookDirectory[], "test.cdf"],

 wrapper,

 WindowSize -> {1100, 1000},

 Method -> "Standalone",

 Target -> "CDFPlayer",

 Deployed -> True

 ]



CloudDeploy[

 ExportForm[wrapper, "CloudCDF"],

 Permissions -> "Public"

 ]
POSTED BY: nik tsak

Both the CDF and the notebook versions of the code run smoothly. It all goes south when it gets deployed on the cloud!

As I mentioned above, there could be some commands you are using that are not supported in the Cloud. Just as there are some commands not supported/allowed to be used in a demo. In the link I gave above, I was trying to make a list of what works and what does not work in the Cloud. I think such a list should be made by WRI. May be there is one, I never seen it. For example, you are using ToExpression, which I know not supported for a demo, (due to it not being safe). May be that is the problem. Try to recode the program without the need to use ToExpression and see if that works. Or better, make a small CDF that uses ToExpression in some way just to see if it deploys and runs Ok on the Cloud. If it does not, then you know it is this command that is causing the problem.

POSTED BY: Nasser M. Abbasi
Posted 10 years ago

I understand what you are saying.

I highly doubt ToExpression is breaking the code, although I cannot be 100% sure it isn't.

Nevertheless I'm tired of wasting my time on something like that. It took me two days to put the whole thing together with the sole purpose of making it available on the cloud only to find out that I can't.

Anyway,

Thank you Nasser for your input. :)

POSTED BY: nik tsak

This works just fine (though of course a slider in the cloud is kind of lame ...):

wrapper = 
  Manipulate[
   main[s1, s2, s3], {{s1, 95, "Slider 1"}, 1, 99, 
    1}, {{s2, 5, "Slider 2"}, 1, 99, 1}, {{s3, 50, "Slider 3"}, 1, 99,
     1}, Initialization :>
    (func1[s1Val_: 0.95, s2Val_: 0.05] := RandomReal[{0, 1}, 2];
     func2[s3Val_, s1Val_: 0.95, 
       s2Val_: 0.05] := {{{"Res1", 10^6 RandomReal[]}, {"Res2", 
         10^6 RandomReal[]}, {"Res3", 10^6 RandomReal[]}, {"Res4", 
         10^6 RandomReal[]}}, 
       Table[{StringJoin["Res5", ToString[i]], RandomReal[]}, {i, 1, 
         10}], Table[{StringJoin["Res6", ToString[i]], 
         RandomReal[]}, {i, 1, 5}], 
       Table[{StringJoin["Res7", ToString[i]], 10^6 RandomReal[]}, {i,
          1, 5}]};
     func3[x_] := 
      Which[x === "Res71", RGBColor[{0., 0.4918, 0.7778}], 
       x === "Res72", RGBColor[{1., 0.1799, 0.1111}], x === "Res73", 
       RGBColor[{1., 0.2222, 0.2523}], x === "Res74", 
       RGBColor[{0.3011, 0.6667, 0.}], True, Gray];
     main[s1Val_Integer, s2Val_Integer, s3Val_Integer] := 
      Module[{list1, val1, array1, grid1, grid2, tmp, chart}, 
       list1 = func1[s1Val, s2Val];
       val1 = Rescale[s3Val, {0, 1}, list1];
       array1 = func2[val1, s1Val, s2Val];
       grid1 = 
        Grid[Prepend[
          Reverse /@ 
           MapAt[N[10^-3 Round[10^3 #/10^3]] &, 
            array1[[1]], {All, 2}], {Style["some text", Bold, 
            Smaller], ""}], Alignment -> Right];
       grid2 = 
        Grid[Prepend[array1[[4]], {"", Style["some text", Bold]}], 
         Alignment -> Right];
       tmp = (array1[[4]] // Reverse // Transpose);
       chart = 
        PieChart3D[tmp[[2]], ChartLabels -> tmp[[1]], 
         ChartStyle -> (func3 /@ tmp[[1]]), ImageSize -> Medium, 
         PlotLabel -> Style["some text", Larger, Bold], 
         SectorOrigin -> {Automatic, 1}];
       Column[{chart, 
         Grid[{{grid2, grid1}}, Dividers -> {{False, True}, False}], 
         Framed[Style["some text", 11, Bold, Darker[Blue]]]}, 
        Center]];), SaveDefinitions -> True];
CloudDeploy[wrapper, Permissions -> "Public"]
POSTED BY: Rolf Mertig
Posted 10 years ago

I chose to enclose Manipulate[] in a DynamicModule[] because I had to hide away some intermediate definitions that are essential to the computation

I have tried losing DynamicModule[] and nothing changed

POSTED BY: nik tsak
Posted 10 years ago

Thank you very much for your response!

I really appreciate the explanation.

I haven't run it yet, but what you're saying makes some sense.

Using strings instead of symbols is not a practical solution for me in this instance because of the way the actual code is written-I would have to re-write the whole thing from scratch! I'm not sure right now how Replace might have worked out in the actual code but it has intuitive appeal.

But it really doesn't matter. The window of opportunity for that piece of code is gone.

Now I will know next time not to mix symbols and strings like that.

That was really informative :)

POSTED BY: nik tsak
Posted 10 years ago

Thank you for taking the time to work through the code

What is wrong with the sliders on the cloud?

POSTED BY: nik tsak
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract