Python processing how to link with Meteor
<p>I have a python script that do some processing over a database of files, the script produce some plots and other relevant numbers as consequence of the analysis. I'm building a Meteor App and what i want , is show the results from my python script inside a Meteor template.</p>

<p>what i wnat is that the entire app works like this :</p>

<p>1) upload file to the database ( done )
2) a button to start the processing of the file by the python script
3) show the results inside the meteor app</p>

<p>so far i have follow <a href="https://forums.meteor.com/t/meteor-python/2563/6" rel="nofollow">this</a> and i'm able to run the script from a meteor button, but how can i use the data generated by the script ( including some plots and relevant numbers) to populate the meteor template? </p>

<p>Thanks for your answer StackOverflow :) </p>

<p>In the Meteor Method use the following code :</p>

<pre><code>'methodName':function(){
        new Fiber(function(){
            console.log('test python file');
            var file_path = process.env.PWD + "/path_to_file/hello.py";

            exec("python " + file_path, function (error, stdout, stderr) {
                if (error) console.log('error'+error);
                if (stdout) console.log('stdout'+stdout);
                if (stderr) console.log('stderr'+stderr);
            });
        }).run();
    }
</code></pre>

<p>Here <code>stdout</code> contains the output of the python code. You cannot directly use the plots generated from the python as it will be difficult to integrate, however, you can send the data to the meteor and use meteor to generate the plots on the client side using libraries like d3js or plot.ly.</p>

<p>The output data can be a matrix or JSON or can be even a file, which the meteor subsequently reads and does the operation.</p>

<p>EDIT 1: Example to use it in template</p>

<pre><code>'methodName':function(){
            new Fiber(function(){
                console.log('test python file');
                var file_path = process.env.PWD + "/path_to_file/hello.py";

                exec("python " + file_path, function (error, stdout, stderr) {
                    if (error) console.log('error'+error);
                    else if (stdout) return stdout;
                    else if (stderr) console.log('stderr'+stderr);
                });
            }).run();
        }
</code></pre>

<p>//In Helper</p>

<pre><code>'helper1': function(){
return Meteor.call('methodName');
}
</code></pre>

<p>//In Html</p>

<pre><code>{{heplper1}}
</code></pre>

javascript python meteor