Message Boards Message Boards

Front End/Back End design?

Posted 8 years ago

Background Info: I have created a notebook (in the Wolfram Language using the Desktop environment) that generates a user interface. I have also created 15 other notebooks that generate different kinds of data for the interface, if the user calls for it. Currently the 15 "back end" notebooks are set up as APIFunctions and can be deployed so that a $post request from an HTML page or query via a URL will return the data. That was fine when my front end was an HTML page, but now I'm trying to switch it so that the user interface is written in Wolfram Language (Grid[], Pane[], Button[], etc.) instead of HTML.

Main Question: What functions do I need to use so that the front end UI (notebook? Instant API?) asks for and gets data from the back end (cloud object? Instant API?)?

Obviously, I'm a beginner in the Wolfram Language, so please be patient with my cluelessness, and answer in a way that will make sense to me as I climb the learning curve. : )

Thanks in advance,

Mark

POSTED BY: Mark Greenberg
5 Replies
Posted 8 years ago

As so often happens, a good night's sleep and fresh eyes suggest solutions to what the night before seemed like an intractable obstacle. This morning I realized that if the back end was displaying data in a browser window, but returned $Failed when called by my front-end code, then there was something wrong with the front-end code. I rewrote the critical parts of the code, those quoted above. To my surprise and delight, it worked perfectly (okay, not perfectly, but it did work). Even the images came through, though they were being sent as humongous strings of RGB values!

So why didn't it work before? I'm not positive, but here is a possible explanation: I was copying the URL for the HTTPRequest function from the output cell when I deployed a back-end cloud object, and pasting it inside the brackets of the HTTPRequest function. After I would type quotation marks around the URL, sometimes the color-coding would indicate that it still wasn't a string. I dismissed this as a glitch in the color coding. The code, when run, would also say that I lacked a closing ] when in fact the ] was there. I have come to realize that there are a lot of hidden characters in Wolfram code (escape characters, cell formatting characters, etc.) that you can't see unless you examine the FullForm of it, and I now believe that the URLs I was copying must have contained hidden characters that prevented the code from working.

In any event, it is now working well enough for me to proceed with the project. It's a hobby project of mineĀ—serious, but not commercial. If anyone is interested to know more about it (or even contribute), let me know. We can communicate further outside of the forum.

POSTED BY: Mark Greenberg
Posted 8 years ago

Okay, so I installed version 11 of the Wolfram Desktop programming environment. Thanks for pushing me that direction, Christopher. And now the function HTTPRequest is available to me. I've been playing around with that function and my existing constructs, but I'm not quite clear yet on how it all should work.

My backend cloud objects output a list of four items:

  1. a question in the form of a string, or a Wolfram expression, or a combo of both
  2. a number representing which of the four choices is the correct answer
  3. a list of four choices, each of which could be a string, an expression, or a number
  4. an image (or Null if the question has no image)

I have 15 notebooks, each for a different category of question (algebra, anatomy, etc.). Right now, each notebook can generate five different kinds of questions (answers, choices, images). When I deploy the notebooks, they still produce the four pieces of data, but in a string representation.

Here is a link to the "Numbers" category cloud object. If you refresh the browser window, it will randomly generate a new set of data each time.

As mentioned above, the front-end user interface was originally an HTML page using Javascript for interactivity and MathJax to format the math. I ran into too many limitations with this setup, especially formatting the math. (The TeXForm function, for example, didn't work when deploying to the cloud, so I had to manually format all the LaTex markup.) Before long, I began to think that a better way to accomplish my goal was to make the interface in Wolfram Language.

So I wrote enough of the interface in Wolfram Language to check whether I can request and get data from the back end files, and then work that data into the user interface. So far, the "Numbers" data goes into the UI perfectly, even the Wolfram expressions display properly. However, all of the other backend cloud objects I've tried return $Failed instead of the data to the UI. They seem to return valid data when accessed through a browser:

algebra cloud object

geometry cloud object

The code I am using to request and then parse the data is this:

req = HTTPRequest[ "https://www.wolframcloud.com/objects/655db1d7-b9c7-40f4-8672-4cb58988dbf6"];
reply = URLRead[req];
returnData = ToExpression[reply["Body"]];
q = returnData[[1]];
ans = returnData[[2]];
mixed = returnData[[3]];
pic = returnData[[4]];

After I parse it, I display the various parts (question, choices, and image) as appropriate in the user interface.

I am still learning all of this (HTTP requests, Wolfram programming, etc.) so it is hard to isolate what the problem might be. And although I'm not there yet, I know that images and graphics objects will be an issue because right now that data is being returned as super-long strings.

Any help would be appreciated. I could share files/code outside of the discussion if that is better.

Thanks,

Mark

POSTED BY: Mark Greenberg

You'll want to use the new version 11 function HTTPRequest.

I'd be delighted to see you post a simple code example that demonstrates how an HTTPRequest in your front end UI notebook calls a back end instant API cloud object.

Posted 8 years ago

Sounds like just what I need, but I cannot seem to find a link to upgrade/download version 11 of the Wolfram Desktop. Any thoughts on where I might get the new version?

POSTED BY: Mark Greenberg

Sign in (or create an account) on the Wolfram User Portal. On the My Products and Services page there should be an Upgrade Available link, or contact Wolfram Sales.

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