Is it Possible to use PHP to select a file to pass into an R script as an argument to be operated on? -


I am currently using a batch file that contains the following line code:

  C: \ r \ bin \ rcmd.exe bat " /shares.r"  

It opens and runs the following code:

  Library (ggplot2) library (xml) test.df & lt; --xmlToDataFrame (file.choose ()) test.df sapply (test.df, class) test.df $ timeStamp & lt; - striptime (as.character Test.df $ timeStamp), "% H:% M:% OS") test.df $ value & lt; - as.numeric (as.character (test.df $ value)) sapply (test.df, class) option (test.df $ priceStamp) (test.df $ timeStamp) test.df $ timeStamp and lieutenant ("digits. Secs "= 3) with summary (test.df) (test.df, plot (timestamp, price)) SD; - test.df [1, "timestamp"] + cumsum (runif (7) * 60) summary (test.df) qplot (timestamp, value, data = test.df, geom = c ("point", "line" )) Price & lt; - Summary (test.df $ value) print (value) dput (test.df)  

Is it possible to use a php form to select a file and this is a debate As R. Scr file.choose () command ipt there, I would be running it from a local host?

I have not used r before, although I can put some light on the PHP side of things ...

A short answer: No, not with file picker.

Long answer: Although you choose a file picker ( & lt; input type = "file" & gt; ) graphically, to actually complete the file path It is impossible to get it

Then you have two options:

1) You can only select files from the pre-known selection

  & php R scripts using something like $ available_r_scripts = array ('shares.R', 'foo.R', 'bar.R'); ? & Gt; Choose a script: & lt; Select name = "R_script" & gt; & Lt ;? Php foreach ($ available_r_scripts $ as script) {? & Gt; & Lt; Option value = "& lt ;? php echo $ script?" & Gt; & Lt ;? Php alo $ script? & Gt; & Lt; / Option & gt; By & lt;? }? & Gt; & Lt; / Select & gt;  

2) If you are actually uploading R script you will normally use the file-uploading form, press the uploaded file name on the server, then feed it, however you can It must be used in your R script:

form.html

  & lt; Form action = "run_script.php" method = "POST" encrypt = "multipart / form-data" & gt; & Lt; Input type = "file" name = "r_script" & gt; & Lt; Input type = "submit value =" run script ">  

run_script.php

  & lt; ? Php $ filename = $ _FILES ['r_script'] ['tmp_name']; // $ filename now has the full name and path of the script you uploaded. // call R script here  

Comments