Playing with python-rpy2

The goal was to prepare a little prototype to show the potential of R (r-cran) when used via its Python bridge python-rpy2, then show the results in a web application, for example, using django.

In this example (in spanish) we take a CSV database and use R to present some calculations. The code of the example is published here, you can browse it, download or even clone using mercurial.

Thanks to Martin Sanguinetti who have motivated me and told me the R basics to make this example.

An example plot using python-rpy2

[A classical example plot using python-rpy2]

Tags: , , , , ,

6 Responses to “Playing with python-rpy2”

  1. mauricio Says:

    Hi,
    Very interesting post, thanks!
    I’m wondering if you could elaborate a bit more on the example.
    For example, how do you call your python script within django? Do you call it from views?
    Thanks for your help.

  2. anibal Says:

    Thank you mauricio,
    Yes, the Python code you can see in the “this example” link in the post (which is “http://anibalpacheco.com:8000/gini/”) is just the code I have in my django view, the view only adds its definition (def …) at the top, as you can imagine, and its return sentence, which is a call to render_to_response.

    Let me know if you want to see the full project code with the template and urls, etc. I can send it to you or publish somewhere.

    Thanks for your comment.

  3. mauricio Says:

    Hi Anibal,

    Seeing the template and urls, etc would help me a lot, thank you.

    I am doing the following type of plots in R.
    http://napoli.rutgers.edu/site_media/CG_CG.png

    Which I would like to make dynamically using your example. I am using django to display some data from RiboNucleicAcid (RNA) Structures.

    Thank you very much,

    Mauricio

  4. anibal Says:

    Hello Mauricio, nice plot you’re doing :)

    I’ve just published the whole code of my example here [0] you can browse the link, download or even clone the repository using mercurial [1], using exactly the same url.

    The repository it’s a django-project that should work out-of-the-box if you have all the dependencies: django, R with “ineq” package and rpy2.

    The files include a short version of the database because I don’t know if I can publish it all. Hope it can help for your project.

    [0] http://hg.anibalpacheco.com/rpy2-example
    [1] http://mercurial.selenic.com

    best regards.
    Anibal.-

  5. Brian Jain Says:

    Thanks for your article. I am new at python and this was a big help.

  6. anibal Says:

    Thanks for your comment Brian.

    Btw, the example seems broken now, maybe due to a system upgrade, but I’ll fix ill later.

    cheers

Leave a Reply