Message Boards Message Boards


How can I create a data import button for Player Pro?

Posted 7 years ago
5 Replies
7 Total Likes

Hi everyone,

Can't seem to create a button for importing data from external files that could be used by those opening a notebook with Player Pro. I tried the example at the bottom of

by doing this

 data = Import[dataFilePath, "CSV"],
 Button["Load data...", dataFilePath = SystemDialogInput["FileOpen"]]

but I get Failed or Canceled. Seems as though the file path is not saved to dataFilePath. What am I doing wrong?


5 Replies
Posted 7 months ago

Many thanks Gustavo It works ! The best new of the day for me today. So that I can go to sleep earlier today !

Posted 7 months ago

Hello Yvan,

I think the issue is that you need to store the result of the import into a variable that is shown somewhere else and wrapped inside a Dynamic[]. For example:

DynamicModule[{result = "please load file"},
  Button["Click Here", result = Import[SystemDialogInput["FileOpen"]],
    Method -> "Queued"]}]
Posted 7 months ago

.... seems not to work anymore ...

I would just open a file (picture) with a button, but I don't understand why my code doesn't work ...

Button["Click Here",
 Method -> "Queued"

Thanks for an help ...


Hi David,

Works like a charm. Thank you for the crystal-clear explanation. I'll do my homework on Catch and Throw as I haven't had occasion to use them before.

Thanks again,


Here is a button that you can use that will import a file into a global parameter called myData:

Button["Import Data",
 myData = Catch@Module[{filePath},
    filePath = SystemDialogInput["FileOpen"];
    If[filePath === $Canceled, Throw[$Failed]];
 Method -> "Queued"

The Method -> "Queued" option keeps the process from timing out since dynamic behaviors have a time limit on them when they are preemptive (as buttons are). The Catch and Throw just help to keep things nice if you cancel the system dialog.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract