2017-04-04 4 views
0

R 스크립트에 매개 변수를 보내는 ASP.NET MVC 응용 프로그램이있는 경우 R 스크립트는 파일을 생성하여 폴더에 로컬로 저장합니다. 이 프로세스는 Visual Studio를 통해 내 로컬 컴퓨터에서 완벽하게 작동하지만 IIS를 게시하고 사용하면 출입니다. 아래는 R.NET을 초기화하고 AJAX를 통해 내 뷰에서이 값을 가져 오는 방법입니다.R.NET이 로컬에서 작동하지만 IIS에서 작동하지 않는 이유는 무엇입니까?

또한이 두 PATH를 시스템 환경 변수에 넣었습니다.

OS를 다시 시작한 직후 IIS가 작동하는 이유를 아는 분이라면 누구나 감사의 말씀을 전합니다. IIS에서 내가 직면하는 Visual Studio에서 문제가 없다는 것이 이상하게 보입니다.

 [HttpGet] 
    public JsonResult Index1(string modelTypes = null, string fileNames = null, string[] locations = null, string lowerLimits = null, string upperLimits = null, string areas = null, string productivities = null, string[] fobs = null) 
    { 
     @ViewBag.UserName = System.Environment.UserName; 
     string userName = @ViewBag.UserName; 
     //Declare field parameters 
     var strModelTypeValue = modelTypes; 
     string strFileName = fileNames; 
     var strLocationValue = locations; 
     var strLowerLimitValue = lowerLimits; 
     var strUpperLimitValue = upperLimits; 
     string strAreaValue = areas; 
     string strProductivityValue = productivities; 
     string strFobValue = fobs.ToString(); 
     var libraryLocation = "C:/Users/" + userName + "/Documents/R/win-library/3.2"; 

     string rPath = @"C:\Program Files\R\R-3.3.2\bin\x64"; 
     string rHome = @"C:\Program Files\R\R-3.3.2"; 

     //Initialize REngine 
     REngine.SetEnvironmentVariables(rPath, rHome); 
     REngine engine = REngine.GetInstance(); 
     engine.Initialize(); 

     if (fobs.Length > 1) 
     { 
      strFobValue = string.Join(" ", fobs); 
     } 
     else 
     { 
      strFobValue = "ALL"; 
     } 




     //Declare R Script path 
     var rScriptPath = "C:/Users/" + userName + "/Documents/R/RWDir/Loop_Optimization.R"; 

     //Check to see if there was more than one location selected 
     if (strLocationValue.Length > 1) 
     { 

      foreach (var item in strLocationValue) 
      { 
       //Set string location to each location value in loop 
       var strlocation = item; 

       //Add values to parameter list 
       var myParams = new List<string> 
       {  

        strModelTypeValue, 
        strFileName,    
        strlocation,     
        strLowerLimitValue, 
        strUpperLimitValue, 
        strAreaValue, 
        strProductivityValue, 
        strFobValue, 
        libraryLocation 

       }; 

       //Set myParams as arguments to be sent to r script 
       engine.SetCommandLineArguments(myParams.ToArray()); 
       engine.Evaluate("source('" + rScriptPath + "')"); 
      } 

     } 
     //Only one location specified, no need to loop 
     else 
     { 
      foreach (var item in strLocationValue) 
      { 
       //Set string location to each location value in loop 
       var strlocation = item; 
       var myParams = new List<string> 
       { 

        strModelTypeValue, 
        strFileName, 
        strlocation, 
        strLowerLimitValue, 
        strUpperLimitValue, 
        strAreaValue, 
        strProductivityValue, 
        strFobValue, 
        libraryLocation 
       }; 

       engine.SetCommandLineArguments(myParams.ToArray()); 
       engine.Evaluate("source('" + rScriptPath + "')"); 
      } 
     } 
     //engine.Evaluate("source('" + rScriptPath + "')"); 
     //engine.Dispose(); 
     return Json("success", JsonRequestBehavior.AllowGet); 

    } 
+0

웹 응용 프로그램이 IIS에서 가끔 작동하지만 OS를 다시 시작한 후에 만 ​​다시 중지됩니다. – Jwoody30

답변

-1

프로세스를 첨부하여 디버깅을 수행 했습니까?

+0

내가 생각하는 engine.Initialize(); 이로 인해 문제가 발생합니다 –

+0

engine.Initialize() 대신 IIS에서 작업 할 수 있습니까? IIS에 많은 문제가 있었기 때문에 지금은 데스크톱 응용 프로그램으로 다시 만들고 있습니다. – Jwoody30