1
$\begingroup$

I'm working remotely on the Wolfram Engine bundled with the Raspberry Pi and I want to export a manipulatable plot as a CDF without needing to have the front end open. So for example, the following works to export a plot as a png:

plt1=Plot[Cos[x],{x,-6,6}] 
UseFrontEnd[Export["~/plt.png",plt1]]

which creates a .png of the desired plot. My naive hope was that I could create a manipulatable plot in much the same fashion, i.e.

plt=Manipulate[Plot[Cos[-x+t],{x,-1,1}],{t,-4,4}]
UseFrontEnd[Export["~/mani.cdf",plt]]

but I see now that hope was misguided as it did not work. Could anyone show me a way to tell the backend to use the frontend to make me a CDF, or is this somehow not possible? All the sources for creating CDFs that I've seen involve going through the menus in a notebook interface which necessitates that I actually interact with the front end which is inconvenient for me.

$\endgroup$
2
$\begingroup$

If you want to export a CDF document (or a notebook file) you should export a notebook expression. The easiest way to generate a notebook expression for you case is probably this:

UseFrontEnd[Export["~/mani.cdf", DocumentNotebook[{plt}]]]

There are several other ways to achieve the same and thing and depending on what your real use case is other ways might work better. Be warned that when exporting that way you might have to take extra care to provide all the functionality / definitions that your code needs to make the exported CDF document work as desired.

As Gustavo Delfino mentioned, instead of UseFrontEnd from the "JLink`" package you might want to use the newer "System`" symbol UsingFrontEnd. For a bit more information about the two and their differences see e.g. here UseFrontEnd is not working the same in version 10.4 (documentation for the two seems to be quite minimalistic and especially gives no clear indication about whether one of the two is deprecated or to be favoured...).

$\endgroup$
  • 1
    $\begingroup$ I didn't know about UseFrontEnd but I am using UsingFrontEnd for a daily email report that I generate (with attached CDF & PDF files). After comparing the documentation I think that UsingFrontEnd is better as it doesn't require a Needs["JLink`"] before using it. $\endgroup$ – Gustavo Delfino Nov 4 '16 at 18:35
  • $\begingroup$ good point, I keep forgetting about that, in fact here I didn't even realize what I was using as I just copied the OPs code. Will change that in a minute... $\endgroup$ – Albert Retey Nov 5 '16 at 9:38

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.