Message Boards Message Boards

Create GUI Button for the Manipulate to export selected data?

Posted 5 years ago

Hi there,

can someone provide an example of how to include a button on the manipulate command that would export the data you select?

SetOptions[
  Plot, {ImageSize -> 400, AspectRatio -> 0.2, 
   ImagePadding -> {{100, 1}, {10, 10}}, Frame -> True}];
Manipulate[
 Column[{Plot[x, {x, 1, 4}, Epilog -> {Line[{{y, 0}, {y, 10}}]}],
   Plot[x^z/4^z, {x, 1, 4}, Epilog -> {Line[{{y, 0}, {y, 10}}]} ]}], 
 {y, 1, 4}, {z, 1, 10, 1}]

Thanks

POSTED BY: T P
3 Replies

Perhaps something like this?

SetOptions[
   Plot, {ImageSize -> 400, AspectRatio -> 0.2, 
    ImagePadding -> {{100, 1}, {10, 10}}, Frame -> True}];

path = FileNameJoin[{$HomeDirectory, "DeskTop", "plots.png"}];

Manipulate[
   plots = Panel @
     Column[
        {Plot[x, {x, 1, 4}, Epilog -> {Line[{{y, 0}, {y, 10}}]}], 
         Plot[x^z/4^z, {x, 1, 4}, Epilog -> {Line[{{y, 0}, {y, 10}}]}]}],
   {plots, None},
   {y, 1, 4},
   {z, 1, 10, 1},
   Row[
      {Spacer[140],
       Button["Export Plots", Export[path, plots], 
         Method -> "Queued", ImageSize -> Automatic]}],
   TrackedSymbols :> {y, z}]

panel

Clicking on the button, produces the following PNG:

plots

POSTED BY: Morton Goldberg
Posted 5 years ago

I've been told to use the save function instead of export, what is this?

https://reference.wolfram.com/language/ref/Save.html

When would it be advantageous to use this feature?

POSTED BY: T P

I used Export because your question said "a button ,,, that would export the data". You didn't mentions Save.

Save writes its output to a file as front-end code; i.e., in the same form as if it were stored in an Mathematica notebook file. Export can write its output in large number of formats. In my code I chose to have it write the Manipulate expression's plots in PNG format.

It is easy to modify my Button code to use Save in place of Export. Like so:

path = FileNameJoin[{$HomeDirectory, "DeskTop", "plots.wl"}]

Manipulate[
  plots = 
     Panel @
    Column[
       {Plot[x, {x, 1, 4}, Epilog -> {Line[{{y, 0}, {y, 10}}]}], 
        Plot[x^z/4^z, {x, 1, 4}, Epilog -> {Line[{{y, 0}, {y, 10}}]}]}],
    {plots, None},
    {y, 1, 4},
   {z, 1, 10, 1},
   Row[
     {Spacer[140],
      Button["Save Plots", Save[path, plots],
        Method -> "Queued", ImageSize -> Automatic]}],
   TrackedSymbols :> {y, z}]

Notes

  • The file path has been changed to give the file the extension wl.
  • You can retrieve the plots with Get[path]
POSTED BY: Morton Goldberg
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract