Inspired by JS Fiddle I'd like a way to write a little snippet of Mathematica code and then get it to show up on a website so people can play with it. I know I could put it into a cloud notebook, but I'd like this to be free.

So...how do?


I made use of an undocumented API for Mathematica cloud notebooks to write a little set of JavaScript functions that can be used to do just this, parsing Mathematica cells out of a browser URL. I then put this up here: https://www.wolframcloud.com/objects/b3m2a1/WLFiddle

I have to other versions of this for slightly different use cases, too:

It uses a free sandbox cloud notebook, so it doesn't actually cost me anything (I think).

Now all you need to do is basic64 encode your cell content and pass it in. Or you can use a little package I wrote for this:

<< https://github.com/b3m2a1/mathematica-tools/raw/master/WLFiddle.wl

"MakeWLFiddle[nb] turns nb or its current selection into a fiddle URL
MakeWLFiddle[cells] turns a set of cells into a fiddle URL"

We can call this on a notebook selection and it'll format a URL for us to use automatically, like say this one that provides the following Manipulate:

  q1/Norm[{x, y} - p[[1]]] + q2/Norm[{x, y} - p[[2]]], {x, -2, 
   2}, {y, -2, 2}, Contours -> 10], {{q1, -1}, -3, 3}, {{q2, 1}, -3, 
  3}, {{p, {{-1, 0}, {1, 0}}}, {-1, -1}, {1, 1}, Locator}, 
 Deployed -> True]

I just put that in a notebook and called


You can also select a subsection of a notebook and evaluate the same in a Button and it'll just package up the selected cells. This should work for any number of cells, but won't work for big data since I cooked everything into the URL query.

Also look at the Options:

{"ShortenURL" -> True, "BaseURL" -> Automatic}

"BaseURL" can be an arbitrary URL or "Delayed" or "Embed".

Warning: if WRI gets mad at me about this at any point this may disappear

  • $\begingroup$ The three wolframcloud.com links seem no longer working. Still fixable? $\endgroup$
    – Meng Lu
    Jan 14 at 1:43

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.