-3
$\begingroup$

I'm building a little interface, which consists only of a button, as you can see here:

Button["File Input",
   file = Import[SystemDialogInput["FileOpen"]]; 
            Print[principalFunction[file]]]

Now I'd like to insert the produced graphic and the button inside a Manipulate. Note that I'm not using Plot, Plot3D, etc. -- the graphics are produced by principalFunction as the final result of evaluating many other functions.

$\endgroup$
  • 1
    $\begingroup$ Instead of an image give us the code? Adapt it so we don't need the file? :) Or you can just provide the file as well. $\endgroup$ – Öskå Apr 24 '14 at 13:54
  • $\begingroup$ ok, I've done what you asked $\endgroup$ – Lory Lory Apr 24 '14 at 14:03
  • 1
    $\begingroup$ Try Module[{file = {0, 0}}, Panel[Column@{Button["File Input", file = ToExpression@Import[SystemDialogInput["FileOpen"], "Data"];], Dynamic@ListLinePlot@file}]]. The important parts here are Module, Panel (for the Manipulate-lookalike) and Dynamic for the update :) Works with a text file containing {{1,0},{1,1}}. $\endgroup$ – Öskå Apr 24 '14 at 14:12
2
$\begingroup$

Not really a fancy answer but questions need to be answered and I hope this answers the (quite unclear) question.

As mentioned in the comments the important parts in the following codes are Module, Panel for the Manipulate lookalike and Dynamic for the update. Since you mentioned that you were not using Plot here is an example with a Graphic entity.

Module[{file = {{0, 0}}, r = 1},
  Panel[Column@{
    Button["File Input",file = ToExpression@
      Import["http://pastebin.com/download.php?i=eaey3Ehk"]; r = .5;],
    Dynamic@Graphics[Disk[#, r] & /@ file]}]]

enter image description here

In your case you would have principalFunction@file instead of Graphics[Disk[#, r] & /@ file] and file = Import[SystemDialogInput["FileOpen"]]; with the operations (such as ToExpression in my case) you need to in order to use your data after using Import.

Version with Manipulate (thus no Dynamic nor Panel):

Module[{file = {{0, 0}}, r = 1},
  Manipulate[Graphics[Disk[#, r] & /@ file, ImageSize -> {200, 200}], 
    Button["File Input", file = 
      ToExpression@Import["http://pastebin.com/download.php?i=eaey3Ehk"];  
      r = .5;]]]
$\endgroup$
  • $\begingroup$ This was very helpful. Thank to you I've been able to help a mate...It's not clear to me the second example you wrote, the one with Manipulate but the first was successful! $\endgroup$ – Lory Lory Apr 29 '14 at 15:05
  • $\begingroup$ I'm glad I could help :) $\endgroup$ – Öskå Apr 29 '14 at 16:05

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.