How Do I Convert a Mathematica Notebook into a Web Application?

This simple example shows how, in four simple steps, you can convert a Mathematica notebook into an interactive web application running on a webMathematica server. Of course, webMathematica gives you many more options to dress up your web applications with technologies such as JavaScript, applets, or PHP, but for a bare-bones web application, this is all that is involved.

The notebook we start out with is an electrical engineering example that analyses a simple electric circuit displaying chaotic behavior.


Steps

  1. The first step is to export the notebook as an HTML file called circuit.msp using the Mathematica command SaveAs...Special.

  2. In the next step, extract the code and save it as a Mathematica package file.

  3. Then add an HTML form with the necessary <Mathlet> tags to load the Mathematica package file created in the last step and to provide a user interface to your HTML file.

    [*--Instruct the msp to call itself--]

    <FORM ACTION="circuit" METHOD="POST">

    [*--Load circuit.m, the package file created in step 2--]

    <%Mathlet Get["circuit`"]; %>

    [*--Add instructions for the user--]

    <p>Enter an input voltage and hit return</p>

    [*--Create a standard input field and insert a default value--]

    <INPUT TYPE="TEXT" NAME="voltage" ALIGN="LEFT" SIZE="3" VALUE ="<%Mathlet MSPValue[$$voltage, ".5"] %>"> V

    [*--Call the plotting function Parametric defined in circuit.m and pass the input voltage--]

    [*--MSPBlock and MSPShow are two MSP functions for preprocessing the input and displaying a graphic, respectively--]

    <p><%Mathlet MSPBlock[{$$voltage}, MSPShow[Parametric[$$voltage]]] %></p>

    [*--Close the HTML Form tag--]

    </FORM>

  4. The only thing left is to save the files on the webMathematica server, and then the web application "A Chaotic Circuit" is finished. With a bit more work, the example can have a new look.