0

I want to create some plots using R. Save them as .png or .jpg image in R. And then display the image on the web page.

can you please tell me how to call an R script from c#, asp.net. I have found that R.NET has issues, so I am trying to avoid using it.

Here is my R script:

library(stats)    
library(ggplot2)    
getwd()    
setwd("C:\\Users\\..................")    
mydatadata <- read.csv(file = "boxplot_test_data.csv", header = TRUE, sep = ",")    
ggplot(mydata, aes(y=Y, x=X, fill=fillFactor)) +    geom_boxplot(outlier.color=NA) + geom_point(aes(size=AXI, shape=FA), color="gold", position=position_jitter(width=0.1, height=0))    
ggsave("myggplot2.png")    
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Diana4
  • 53
  • 1
  • 2
  • 9

1 Answers1

0

R has command line executables. There are a few different SO threads with various answers on the best way to do this. For example, see How to run a R language(.r) file using Batch file?

From within C# you can use `System.Diagnositics.Process' to start the executable using your chosen method and wait for the process to exit.:

var myRProcess = new Process {StartInfo = new ProcessStartInfo(processPath)};
myRProcess.Start();
myRProcess.WaitForExit();

Once it has completes your image will be in the the location you saved it to.

From there you can serve the image as you would any image.

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41