Как отправить данные из php из в R скрипт для некоторого prdection на основе этих данных? - PullRequest
1 голос
/ 15 мая 2019

Я создал форму, используя PHP с определенными вопросами, и всякий раз, когда пользователь нажимает кнопку отправки, сгенерированный CSV должен передаваться в сценарий R для прогноза. CSV генерируется, но не передается в сценарий R, помогите пожалуйста

Я пытался использовать exec (); но это не сработало или я делаю это неправильно.

<?php
    if(isset($_POST['submit'])){

    //collect form data
   $Pleasure=$_POST['Pleasure'];
    $Feeling=$_POST['Feeling'];
f(!isset($error)){

        # Title of the CSV
        $Content = "PleasureDoing,Feeling\n";


        //set the data of the CSV
        $Content .= "$Pleasure,$Feeling";

        # set the file name and create CSV file
        $FileName = "formdata-".date("d-m-y-h:i:s").".csv";
        header('Content-Type: application/csv'); 
        header('Content-Disposition: attachment; filename="' . $FileName . '"'); 
        echo $Content;
        exec('C:\\"Program Files"\\R\\R-3.5.1\\bin\\Rscript.exe C:\xampp\htdocs\predict\Rscript.R ');
        exit();
    }
}

//if their are errors display them
if(isset($error)){
    foreach($error as $error){
        echo "<p style='color:#ff0000'>$error</p>";
    }
}
?> 

<form action='' method='post'>

<h2>Little interest or pleasure in doing things</h2>
  <input type="radio" name="Pleasure" value=" Not at all"> Not at all<br>
  <input type="radio" name="Pleasure" value="Sometimes">Sometimes<br>
  <input type="radio" name="Pleasure" value="Several days">Several days<br>
  <input type="radio" name="Pleasure" value="More than half the days">More than half the days<br>
  <input type="radio" name="Pleasure" value="Nearly everyday">Nearly everyday<br>

  <h2>Feeling down, depressed, or hopeless</h2>
  <input type="radio" name="Feeling" value=" Not at all"> Not at all<br>
  <input type="radio" name="Feeling" value="Sometimes">Sometimes<br>
  <input type="radio" name="Feeling" value="Several days">Several days<br>
  <input type="radio" name="Feeling" value="More than half the days">More than half the days<br>
  <input type="radio" name="Feeling" value="Nearly everyday">Nearly everyday<br>

<p><input type='submit' name='submit' value='Submit'></p> 
</form>

SO rather then the code to generate the csv i want the code to send the data to the R scrip, how should i proceed or do it ?

1 Ответ

0 голосов
/ 15 мая 2019
  1. PHP создает файл данных
  2. R читает файл
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...