matplotlib passing parameters from the view

37 views
Skip to first unread message

Paolo Amboni

unread,
May 5, 2016, 3:36:32 AM5/5/16
to web2py-users
I'm trying to build a single function (in a controller) that generate different matplotlib graph..

So the function that generate the stream works fine:
def grafico(title='title',xlab='x',ylab='y' data=.... ):
     fig=Figure()
     ....
     return stream.getvalue()


the function that call the privious works fine but not as i want:


def graf_comp_gior():
    test_id=1 # I need to set the id on the fly
    print response.args # Always none why?
    print response.vars #Always none why?

    rows = db(db.tat.id_test==test_id).select()
    tat=pd.DataFrame(rows.as_list())
    .... #manupulate the data as i need

    graf=grafico(........)
    
    return graf

This is the view with the embedded graph works fine:

{{{extend 'layout.html'}}
<h1>TAT completi per l'analisi {{=variabili['anal']}}</h1>
{{=IMG(_src=URL('graf_comp_gior',args=[argomenti[0],vars=dict('id'=argomenti[0])]))}} How can i pass some data to the previous function?

Do i need to store them in a session?
Thanks!!

Paolo Amboni

unread,
May 5, 2016, 3:53:44 AM5/5/16
to web2py-users
I stored the id in a session variable and it works fine!!
But why the URL helper didn't send the args to the function?

Niphlod

unread,
May 5, 2016, 4:11:45 AM5/5/16
to web2py-users
there's a problem in your syntax.

it's usually URL('blabla', args=[], vars=dict())

while your code reports

args=[..., dict=()]

Paolo Amboni

unread,
May 6, 2016, 2:50:21 AM5/6/16
to web2py-users
Same problem!
the args and var are not passed to the receiving function in this specific case.
(I tried both args and vars alone first).
With session all works fine.

I find very complex the way web2py handle matplotlib plots.
Is there other plotting library that better integrate in web2py framework? 

Niphlod

unread,
May 6, 2016, 3:05:18 AM5/6/16
to web2py-users
if your generated url is /a/c/f/graf_comp_gior?var1=a&var2=b I assure you that those will be passed.
as for the graphing library, I highly suggest to switch to a javascript based solution rather than a python one for any web site.
Reply all
Reply to author
Forward
0 new messages