8
$\begingroup$

I'm excited about the new Mathematica Toolbox for WordPress and have gotten parts of it to work, but I am having trouble bringing in material from the WolframCloud.

Here is the Mathematica code I have used to create a toy Cloud object.

 CloudDeploy[3+4, Permissions -> "Public"]

When I do this I get back the following URL.

https://www.wolframcloud.com/objects/997adccf-b46d-4a03-a515-6a1a12fd3017

I have tested the URL in my browser and, indeed, the Wolfram Cloud is able to compute and display the answer to this challenging math question.

And here is the text of the WordPress code I am using

This is a draft that tries to use Wolfram Cloud

[wlcode]

Plot[sin[x],{x,0,10}]

[/wlcode]

This works.  Yay!

[WolframCloudAPI id="85afebcc-e5c9-4399-a44c-de6b805dd081",image="false"]

Does not work.  Why not?

 

And when I preview this, I do not get the number 7 back; instead I get a little box that shows nothing.

Help!

$\endgroup$
  • $\begingroup$ Your cloud URL doesn't return a number, instead it returns HTML. So what the plugin does is it grabs that HTML and displays it. You have to return only the text you want to display, like in the first example in the documentation for CloudDeploy. $\endgroup$ – C. E. Sep 11 '15 at 8:47
  • 1
    $\begingroup$ I am sorry but I still do not get it. I have tried what you suggested and it still does not work. I very much appreciate the tool that has been created, but I think it would be even more helpful if the following could be provided: (1) the Mathematica code needed to create a CloudDeploy that works and (2) minimal WordPress text that successfully retrieves the results. $\endgroup$ – Seth Chandler Sep 12 '15 at 14:38
  • $\begingroup$ I noticed that you have not accepted any answer to any of your questions, which means either that you have never received a satisfactory answer or that you don't know that you are supposed to "accept" satisfactory answers using the green checkmark underneath the up and down buttons. (If there are several satisfactory answers, you should accept the most satisfactory answer.) $\endgroup$ – C. E. Sep 26 '15 at 19:03
5
$\begingroup$

It is important to note that CloudDeploy[3+4, Permissions -> "Public"] is not an API function, as is required by the WordPress plugin. You should use it together with APIFunction. Also note that shortcodes in WordPress never use commas to separate parameters! In your example you wrote

[WolframCloudAPI id="id",image="false"]

which wouldn't work regardless of what ID you give it. It should be

[WolframCloudAPI id="id" image="false"]

If you take these things into consideration you should get your example to work. However I noticed a bug related to the WolframCloudAPI shortcode with API parameters, so I issued a bug fix. Your WordPress admin panel should tell you shortly that there is an update available.

Deploying an API function

Here are two examples that will work:

CloudDeploy[APIFunction[{
   "rule" -> Restricted["Number", {0, 255, 1}] -> 30, 
   "step" -> Restricted["Number", {0, Infinity, 1}] -> 50
   }, 
  ArrayPlot[CellularAutomaton[#rule, {{1}, 0}, #step], 
    Frame -> False] &,
  "PNG"
  ], Permissions -> "Public"]

and

CloudDeploy[APIFunction[{"x" -> "Integer"}, FactorInteger[#x] &], Permissions -> "Public"]

Retrieving results from WordPress

Let's call the ID of the first API A and the ID of the second API B. The first API returns an image and the second one returns text, this is what determines whether image="false" should be in there. In WordPress, write

[WolframCloudAPI id="A" rule="15" step="25"]

and

[WolframCloudAPI id="B" x="43498" image="false"]

The first example is an image of rule 15 with 25 steps, and the second example is a list representing the factorization of the number 43498. It should look like this when you load the page:

Screenshot

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.