简体   繁体   中英

How to run R script from HTML webpage

I have no experience with R language. I have been given some R scripts that my webpage would run. I am developing a web application where the user uploads a file and the contents of file are saved in a database and a basic scatter plot (using php and d3) is produced with patient names and years. The application would let the user to select any 'dot' of the scatterplot for detailed analysis. When the user does a selection, the application should get the respective row from database with all the fields and write them in a csv file. And feed this csv file to a format conversion R script to produce 'new_format.csv'. After format conversion, new_format.csv has to go to another R script that does the main calculations and stores result in a Rdata file.

How do I run R script from my webpage? Where do I save/store the two intermediate csv files produced during the calculations and how do I feed them forward?? And How do I fetch results from Rdata file and save them in database or draw some graphs using them?

BTW as these R scripts are being provided to me, therefore, I am not allowed to change them. And yes, the R script is designed to read a csv file, that is why I want to convert the selected database row to a csv file.

Thanks in advance !

It sounds like you're asking how to do the data processing on the back-end. If you have R installed on your server, you can use PHP to run commands to execute your R scripts using the shell_exec() function. The command to to execute an R script looks like the following:

R CMD BATCH "--args 'dataPath/input.dat'" script.R

This will produce a script.Rout file with the output or you can have the R script internally output a file with the results. The R script will need to use the following function internally to get the input data file name from the command line:

dataFileName <- commandArgs(TRUE)

That being said this can be done faster using specialized infrastructure such as FastRWeb . Also see How to set up an R based service on a web page for other suggestions.

您可以使用http://www.rstudio.com/shiny/上的 R脚本启动网络服务器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM