2
$\begingroup$

so I've been having trouble getting a dynamic import button to work inside of a manipulate. I have code that takes in a data set (in this case an excel sheet), and I got everything to work fine in the UI at first. But there are some days where my code simply seems not to work.

    Manipulate[DataModelGenerator[data1, Temperature, Rate, 
   alphaseed,  Qseed, Aseed, nseed], Dynamic[Button["import data",   fileFull = SystemDialogInput["FileOpen"]; 
   data1 = Flatten[Import[fileFull], 1]], data1], {Temperature, InputField}, {Rate, InputField},  Grid[{{"Seed Values"}, {Grid[{{"Q", 
   Control@{{Qseed, 18, ""}, 
     ControlType -> InputField}}, {"A", 
   Control@{{Aseed, 29, ""}, 
     ControlType -> InputField}}, {"n", 
   Control@{{nseed, 2, ""}, 
     ControlType -> InputField}}, {"\[Alpha]", 
   Control@{{alphaseed, 1, ""}, 
     ControlType -> InputField}}}]}}]
 , ControlPlacement -> Left]

For UI purposes I would prefer to have the button with the manipulate controls. Thank you for your time.

$\endgroup$
  • $\begingroup$ What when you add Method->"Queued" to the Button? p.s. it seems Dynamic on Button is not needed. $\endgroup$ – Kuba Jul 13 '16 at 13:54
  • $\begingroup$ @Kuba Method->"Queued" without Dynamic works great on Windows 7, Mathematica 10.4.1.0. $\endgroup$ – Jack LaVigne Jul 13 '16 at 14:46
1
$\begingroup$

You could use a FileNameSetter to first select the file, then a button to import the data. For example:

Manipulate[
     DataModelGenerator[data1, Temperature, Rate, alphaseed, Qseed, Aseed,nseed], Row[{Item[FileNameSetter[Dynamic[selectedFile]], Alignment -> Center], 
   Button["Import", 
    data1 = Flatten[Import[selectedFile], 1]]}], {Temperature,InputField}, {Rate, InputField}, 
   Grid[{{"Seed Values"}, {Grid[{{"Q", 
    Control@{{Qseed, 18, ""}, ControlType -> InputField}}, {"A", 
    Control@{{Aseed, 29, ""}, ControlType -> InputField}}, {"n", 
    Control@{{nseed, 2, ""}, 
     ControlType -> InputField}}, {"\[Alpha]", 
   Control@{{alphaseed, 1, ""}, ControlType -> InputField}}}]}}], 
 ControlPlacement -> Left]
$\endgroup$

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.