In this case, I assume you want both, dynamic interactivity and pull large datasets from a database in real time. This can be done with a CDF
notebook, and it doesn't require WebMathematica unless your notebook really needs to do much more computationally intensive work than your example code indicates.
So here are the steps:
Server
Save your dynamic notebook as a CDF
in a directory on your web server where you have enabled serving CDF
- i.e., by adding the following to your .htaccess
file:
AddType application/vnd.wolfram.player nbp
AddType application/vnd.wolfram.mathematica nb
AddType application/vnd.wolfram.cdf cdf
AddType application/vnd.wolfram.cdf.text cdf
Then save your data file (let's call it data.txt
) somewhere on your server, too. I'll assume the URL
of the data file is http://website.com/data.txt
.
Your notebook
In your CDF
file, read the contents of the required data file(s) using a statement like fileContents = Import["http://website.com/data.txt"];
That's all there is to it. Now you can manipulate the contents of data.txt on the client side, and update its contents on the server side if necessary.
Edit
After trying with a computer that doesn't have Mathematica installed, only the CDF player in the Chrome browser, it seems that Import
doesn't work after all.
To solve the original problem of deploying an interactive representation of your data, the best approach therefore seems to be:
- In Mathematica on your local machine, read all the data into your notebook
- With these data, create your interactive element, e.g. a
Manipulate
.
- Save the resulting notebook with the dynamic content as a CDF file.
- Upload this file to your web server, thereby distributing the entire data content together with the interactive interface. This makes it unnecessary to read any external files into the deployed CDF.
An example for this is online at this URL.
This is of course a compromise, and it implies that you'll have to re-evaluate the notebook and save it as CDF every time the data needs to be updated. So, unfortunately, vanilla CDF isn't able to do exactly what you want, both regarding the data file handling and regarding the free-form text input fields.
Now I could go on a rant about how Mathematica deceived me into thinking it's possible, but let's end optimistically by mentioning that there are many other tools (e.g. Javascript libraries) that are more suitable for the task at hand.