[英]How to run R script from HTML webpage
I have no experience with R language. 我没有使用R语言的经验。 I have been given some R scripts that my webpage would run.
我得到了一些我的网页可以运行的R脚本。 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.
我正在开发一个Web应用程序,其中用户上传文件,文件内容保存在数据库中,并使用患者姓名和年份生成基本散点图(使用php和d3)。 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.
当用户进行选择时,应用程序应从数据库中获取包含所有字段的相应行,并将其写入csv文件中。 And feed this csv file to a format conversion R script to produce 'new_format.csv'.
并将此csv文件输入格式转换R脚本以生成'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.
格式转换后,new_format.csv必须转到另一个R脚本,该脚本执行主要计算并将结果存储在Rdata文件中。
How do I run R script from my webpage? 如何从网页运行R脚本? Where do I save/store the two intermediate csv files produced during the calculations and how do I feed them forward??
我在哪里保存/存储在计算过程中产生的两个中间csv文件,以及如何向前馈送它们? And How do I fetch results from Rdata file and save them in database or draw some graphs using them?
以及如何从Rdata文件中获取结果并将其保存在数据库中或使用它们绘制一些图形?
BTW as these R scripts are being provided to me, therefore, I am not allowed to change them. 顺便说一句,因为这些R脚本正在提供给我,因此,不允许我更改它们。 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.
是的,R脚本旨在读取csv文件,这就是为什么我要将选定的数据库行转换为csv文件的原因。
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. 如果在服务器上安装了R,则可以使用PHP来运行命令,以使用
shell_exec()
函数执行R脚本。 The command to to execute an R script looks like the following: 执行R脚本的命令如下所示:
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. 这将产生一个带有输出的script.Rout文件,或者您可以让R脚本在内部输出一个包含结果的文件。 The R script will need to use the following function internally to get the input data file name from the command line:
R脚本将需要在内部使用以下函数来从命令行获取输入数据文件名:
dataFileName <- commandArgs(TRUE)
That being said this can be done faster using specialized infrastructure such as FastRWeb . 话虽如此,使用FastRWeb等专用基础架构可以更快地完成此操作。 Also see How to set up an R based service on a web page for other suggestions.
另请参见如何在网页上设置基于R的服务 。
您可以使用http://www.rstudio.com/shiny/上的 R脚本启动网络服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.