Skip to main content
Additional explanations for the previous revision
Source Link
Jens
  • 97.9k
  • 7
  • 215
  • 510

NowEdit 2

The reason why I could go on a rantwas initially confused about how Mathematica deceived me into thinking it's possible, but let's end optimistically by mentioningthe limitations of the CDF format was actually very simple: the file that there are many other toolsyou get via Save As... CDF behaves very differently from the file that you get by using the menu Deploy > Standalone (ea.gk. Javascript librariesa. Free CDF). It is the free version that areshould be used in order to make content available on the web if your target audience doesn't have Mathematica installed.

However, the "non-free" version from Save As... CDF is what I tried first. It is much more suitablepowerful, but when served as full screen it opens in the browser in the same way that the free CDF does. The non-free CDF then lets you work in your browser window almost as if you were in a Notebook. That's nice, but also confusing when you develop CDF files and lose track of which one was exported in what way. Perhaps it would have been better if Wolfram had reserved the CDF suffix purely for the task at handfree deployed format.

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.

Edit 2

The reason why I was initially confused about the limitations of the CDF format was actually very simple: the file that you get via Save As... CDF behaves very differently from the file that you get by using the menu Deploy > Standalone (a.k.a. Free CDF). It is the free version that should be used in order to make content available on the web if your target audience doesn't have Mathematica installed.

However, the "non-free" version from Save As... CDF is what I tried first. It is much more powerful, but when served as full screen it opens in the browser in the same way that the free CDF does. The non-free CDF then lets you work in your browser window almost as if you were in a Notebook. That's nice, but also confusing when you develop CDF files and lose track of which one was exported in what way. Perhaps it would have been better if Wolfram had reserved the CDF suffix purely for the free deployed format.

Revised my conclusions
Source Link
Jens
  • 97.9k
  • 7
  • 215
  • 510

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:

  1. In Mathematica on your local machine, read all the data into your notebook
  2. With these data, create your interactive element, e.g. a Manipulate.
  3. Save the resulting notebook with the dynamic content as a CDF file.
  4. 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.

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.

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:

  1. In Mathematica on your local machine, read all the data into your notebook
  2. With these data, create your interactive element, e.g. a Manipulate.
  3. Save the resulting notebook with the dynamic content as a CDF file.
  4. 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.

Source Link
Jens
  • 97.9k
  • 7
  • 215
  • 510

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.