librelist archives

« back to archive

advice on flask usage

advice on flask usage

From:
Abhishek Pratap
Date:
2012-10-19 @ 20:17
Hi Guys

This is my first email to the list. I have recently started using Flask
which also happens to be my first attempt with web development so there are
other obvious challenges too :).

I have few basic questions and want to take your advice on how to best
address them through flask.

Background:

1. The main web page gets some data from user, the python code does some
analysis in the background.
2. Now I have results which I want to display to the user. The results
mainly are of 3 types.
     2a. text
     2b. plots
     2c. Text to be displayed as tables.

Questions:

A. If I want to display multiple plots per page should I first create
static images for each plot and then display them ? Is there a more slick
way to display multiple plots per page without creating static images.  I
did come across and example for doing this
https://gist.github.com/1641344but I am not sure how will the same
logic work for multiple images on the
same page.

B. I also want to display tables on the page and give use the capability to
sort them on the page by any column. I am guessing I wud need some sort of
JS code to do so but not sure what JS lib could integrate well with Flask
and require less effort to implement.

C. Lastly if I am asking the user to enter a date on the web page, can I
provide a calendar for the user to select a date. Again some JS library
could help here but I dont have a lot of exp there.

Best,
-Abhi

Re: [flask] advice on flask usage

From:
dorian i
Date:
2012-10-19 @ 20:25
B:

http://datatables.net/release-datatables/examples/basic_init/zero_config.htmlBasically
create a normal table, insert the javascript.
C: http://jqueryui.com/datepicker/ Press the view source.
On Fri, Oct 19, 2012 at 10:17 PM, Abhishek Pratap <apratap@lbl.gov> wrote:

> Hi Guys
>
> This is my first email to the list. I have recently started using Flask
> which also happens to be my first attempt with web development so there are
> other obvious challenges too :).
>
> I have few basic questions and want to take your advice on how to best
> address them through flask.
>
> Background:
>
> 1. The main web page gets some data from user, the python code does some
> analysis in the background.
> 2. Now I have results which I want to display to the user. The results
> mainly are of 3 types.
>      2a. text
>      2b. plots
>      2c. Text to be displayed as tables.
>
> Questions:
>
> A. If I want to display multiple plots per page should I first create
> static images for each plot and then display them ? Is there a more slick
> way to display multiple plots per page without creating static images.  I
> did come across and example for doing this 
https://gist.github.com/1641344but I am not sure how will the same logic 
work for multiple images on the
> same page.
>
> B. I also want to display tables on the page and give use the capability
> to sort them on the page by any column. I am guessing I wud need some sort
> of JS code to do so but not sure what JS lib could integrate well with
> Flask and require less effort to implement.
>
> C. Lastly if I am asking the user to enter a date on the web page, can I
> provide a calendar for the user to select a date. Again some JS library
> could help here but I dont have a lot of exp there.
>
> Best,
> -Abhi
>
>

Re: [flask] advice on flask usage

From:
Sean Davis
Date:
2012-10-19 @ 20:31
On Fri, Oct 19, 2012 at 4:17 PM, Abhishek Pratap <apratap@lbl.gov> wrote:

> Hi Guys
>
> This is my first email to the list. I have recently started using Flask
> which also happens to be my first attempt with web development so there are
> other obvious challenges too :).
>
> I have few basic questions and want to take your advice on how to best
> address them through flask.
>
> Background:
>
> 1. The main web page gets some data from user, the python code does some
> analysis in the background.
> 2. Now I have results which I want to display to the user. The results
> mainly are of 3 types.
>      2a. text
>      2b. plots
>      2c. Text to be displayed as tables.
>
> Questions:
>
> A. If I want to display multiple plots per page should I first create
> static images for each plot and then display them ? Is there a more slick
> way to display multiple plots per page without creating static images.  I
> did come across and example for doing this 
https://gist.github.com/1641344but I am not sure how will the same logic 
work for multiple images on the
> same page.
>

The web page from flask will include links to each image.  Those links
could be to static images or could be to flask routes that generated the
images on-the-fly.  The key is that the first page just includes links.


>
> B. I also want to display tables on the page and give use the capability
> to sort them on the page by any column. I am guessing I wud need some sort
> of JS code to do so but not sure what JS lib could integrate well with
> Flask and require less effort to implement.
>
>
You might look at jQuery datatables.  This doesn't change your flask
application at all, really, other than to include a few lines of javascript
in the page template.


> C. Lastly if I am asking the user to enter a date on the web page, can I
> provide a calendar for the user to select a date. Again some JS library
> could help here but I dont have a lot of exp there.
>
>
I'm no expert, but learning a bit of jQuery and jQuery UI can go a long
way.  Others may have other favorites, though.  Again, on the flask side of
things, not much needs to change as the data will come back to flask as
post data from a form (generally).

Sean

Re: [flask] advice on flask usage

From:
Abhishek Pratap
Date:
2012-10-19 @ 20:50
Hi Sean

On Fri, Oct 19, 2012 at 1:31 PM, Sean Davis <sdavis2@mail.nih.gov> wrote:

>
>
> On Fri, Oct 19, 2012 at 4:17 PM, Abhishek Pratap <apratap@lbl.gov> wrote:
>
>> Hi Guys
>>
>> This is my first email to the list. I have recently started using Flask
>> which also happens to be my first attempt with web development so there are
>> other obvious challenges too :).
>>
>> I have few basic questions and want to take your advice on how to best
>> address them through flask.
>>
>> Background:
>>
>> 1. The main web page gets some data from user, the python code does some
>> analysis in the background.
>> 2. Now I have results which I want to display to the user. The results
>> mainly are of 3 types.
>>      2a. text
>>      2b. plots
>>      2c. Text to be displayed as tables.
>>
>> Questions:
>>
>> A. If I want to display multiple plots per page should I first create
>> static images for each plot and then display them ? Is there a more slick
>> way to display multiple plots per page without creating static images.  I
>> did come across and example for doing this
>> https://gist.github.com/1641344 but I am not sure how will the same
>> logic work for multiple images on the same page.
>>
>
> The web page from flask will include links to each image.  Those links
> could be to static images or could be to flask routes that generated the
> images on-the-fly.  The key is that the first page just includes links.
>
>
>> If I understood this right, I dont think it will work for the way I want
to display these plots. I want to redirect the user to a webpage which has
multiple plots and not just links to the plots. Ideally I would like to
render them using the approach shown on the github example listed ion my
orig mail but not getting ideas to implement the same for multiple plots on
the same web page.



>
>> B. I also want to display tables on the page and give use the capability
>> to sort them on the page by any column. I am guessing I wud need some sort
>> of JS code to do so but not sure what JS lib could integrate well with
>> Flask and require less effort to implement.
>>
>>
> You might look at jQuery datatables.  This doesn't change your flask
> application at all, really, other than to include a few lines of javascript
> in the page template.
>

>> Ok I will try to learn this

>
>
>> C. Lastly if I am asking the user to enter a date on the web page, can I
>> provide a calendar for the user to select a date. Again some JS library
>> could help here but I dont have a lot of exp there.
>>
>>
> I'm no expert, but learning a bit of jQuery and jQuery UI can go a long
> way.  Others may have other favorites, though.  Again, on the flask side of
> things, not much needs to change as the data will come back to flask as
> post data from a form (generally).
>
>>  Could you recommend based on your experience any good source for
quickly picking up on jquery.


>
> Sean
>
>

Re: [flask] advice on flask usage

From:
pronoyc@gmail.com
Date:
2012-10-19 @ 20:58
d3.js <http://d3js.org>

Calculate and pass values to the page. Use JS library to generate them at
run time.

On Sat, Oct 20, 2012 at 2:20 AM, Abhishek Pratap <apratap@lbl.gov> wrote:

> Hi Sean
>
> On Fri, Oct 19, 2012 at 1:31 PM, Sean Davis <sdavis2@mail.nih.gov> wrote:
>
>>
>>
>> On Fri, Oct 19, 2012 at 4:17 PM, Abhishek Pratap <apratap@lbl.gov> wrote:
>>
>>> Hi Guys
>>>
>>> This is my first email to the list. I have recently started using Flask
>>> which also happens to be my first attempt with web development so there are
>>> other obvious challenges too :).
>>>
>>> I have few basic questions and want to take your advice on how to best
>>> address them through flask.
>>>
>>> Background:
>>>
>>> 1. The main web page gets some data from user, the python code does some
>>> analysis in the background.
>>> 2. Now I have results which I want to display to the user. The results
>>> mainly are of 3 types.
>>>      2a. text
>>>      2b. plots
>>>      2c. Text to be displayed as tables.
>>>
>>> Questions:
>>>
>>> A. If I want to display multiple plots per page should I first create
>>> static images for each plot and then display them ? Is there a more slick
>>> way to display multiple plots per page without creating static images.  I
>>> did come across and example for doing this
>>> https://gist.github.com/1641344 but I am not sure how will the same
>>> logic work for multiple images on the same page.
>>>
>>
>> The web page from flask will include links to each image.  Those links
>> could be to static images or could be to flask routes that generated the
>> images on-the-fly.  The key is that the first page just includes links.
>>
>>
> >> If I understood this right, I dont think it will work for the way I
> want to display these plots. I want to redirect the user to a webpage which
> has multiple plots and not just links to the plots. Ideally I would like to
> render them using the approach shown on the github example listed ion my
> orig mail but not getting ideas to implement the same for multiple plots on
> the same web page.
>
>
>
>>
>>> B. I also want to display tables on the page and give use the capability
>>> to sort them on the page by any column. I am guessing I wud need some sort
>>> of JS code to do so but not sure what JS lib could integrate well with
>>> Flask and require less effort to implement.
>>>
>>>
>> You might look at jQuery datatables.  This doesn't change your flask
>> application at all, really, other than to include a few lines of javascript
>> in the page template.
>>
>
> >> Ok I will try to learn this
>
>>
>>
>>> C. Lastly if I am asking the user to enter a date on the web page, can I
>>> provide a calendar for the user to select a date. Again some JS library
>>> could help here but I dont have a lot of exp there.
>>>
>>>
>> I'm no expert, but learning a bit of jQuery and jQuery UI can go a long
>> way.  Others may have other favorites, though.  Again, on the flask side of
>> things, not much needs to change as the data will come back to flask as
>> post data from a form (generally).
>>
> >>  Could you recommend based on your experience any good source for
> quickly picking up on jquery.
>
>
>>
>> Sean
>>
>>
>


-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc

Re: [flask] advice on flask usage

From:
Abhishek Pratap
Date:
2012-10-27 @ 06:00
On Fri, Oct 19, 2012 at 1:58 PM, pronoyc@gmail.com <pronoyc@gmail.com>wrote:

> d3.js <http://d3js.org>
>
> Calculate and pass values to the page. Use JS library to generate them at
> run time.
>
>
> On Sat, Oct 20, 2012 at 2:20 AM, Abhishek Pratap <apratap@lbl.gov> wrote:
>
>> Hi Sean
>>
>> On Fri, Oct 19, 2012 at 1:31 PM, Sean Davis <sdavis2@mail.nih.gov> wrote:
>>
>>>
>>>
>>> On Fri, Oct 19, 2012 at 4:17 PM, Abhishek Pratap <apratap@lbl.gov>wrote:
>>>
>>>> Hi Guys
>>>>
>>>> This is my first email to the list. I have recently started using Flask
>>>> which also happens to be my first attempt with web development so there are
>>>> other obvious challenges too :).
>>>>
>>>> I have few basic questions and want to take your advice on how to best
>>>> address them through flask.
>>>>
>>>> Background:
>>>>
>>>> 1. The main web page gets some data from user, the python code does
>>>> some analysis in the background.
>>>> 2. Now I have results which I want to display to the user. The results
>>>> mainly are of 3 types.
>>>>      2a. text
>>>>      2b. plots
>>>>      2c. Text to be displayed as tables.
>>>>
>>>> Questions:
>>>>
>>>> A. If I want to display multiple plots per page should I first create
>>>> static images for each plot and then display them ? Is there a more slick
>>>> way to display multiple plots per page without creating static images.  I
>>>> did come across and example for doing this
>>>> https://gist.github.com/1641344 but I am not sure how will the same
>>>> logic work for multiple images on the same page.
>>>>
>>>
>>> The web page from flask will include links to each image.  Those links
>>> could be to static images or could be to flask routes that generated the
>>> images on-the-fly.  The key is that the first page just includes links.
>>>
>>>
>> >> If I understood this right, I dont think it will work for the way I
>> want to display these plots. I want to redirect the user to a webpage which
>> has multiple plots and not just links to the plots. Ideally I would like to
>> render them using the approach shown on the github example listed ion my
>> orig mail but not getting ideas to implement the same for multiple plots on
>> the same web page.
>>
>>
>>
>>>
>>>> B. I also want to display tables on the page and give use the
>>>> capability to sort them on the page by any column. I am guessing I wud need
>>>> some sort of JS code to do so but not sure what JS lib could integrate well
>>>> with Flask and require less effort to implement.
>>>>
>>>>
>>> You might look at jQuery datatables.  This doesn't change your flask
>>> application at all, really, other than to include a few lines of javascript
>>> in the page template.
>>>
>>
>> >> Ok I will try to learn this
>>
>>>
>>>
>>>> C. Lastly if I am asking the user to enter a date on the web page, can
>>>> I provide a calendar for the user to select a date. Again some JS library
>>>> could help here but I dont have a lot of exp there.
>>>>
>>>>
>>> I'm no expert, but learning a bit of jQuery and jQuery UI can go a long
>>> way.  Others may have other favorites, though.  Again, on the flask side of
>>> things, not much needs to change as the data will come back to flask as
>>> post data from a form (generally).
>>>
>> >>  Could you recommend based on your experience any good source for
>> quickly picking up on jquery.
>>
>>
>>>
>>> Sean
>>>
>>>
>>
>
>
> --
> Regards,
>
> Pronoy Chopra
> http://blog.pronoy.in <http://www.pronoy.in/about>/
> http://www.twitter.com/pronoyc
>

Hi Guys

I have a follow up question. In order to render plots by calling functions
in the img src tag as suggested above(eg below)

 <img src ="{{url_for('plot1')}}" >

I need to pass computed values which were computed by the function called
as a result of user form submission. This function in turns render the html
template which makes calls to the plot methods ( <img src
="{{url_for('plot1')}}" >) . Each plot method needs to access that
dictionary object computed earlier by the form response function to return
a plot on the fly.

In other words I would like to share a python objects between flask methods
and if possible avoid exchanging them through the browser.

Can I share objects on the server end itself  between the flask methods ?

Thanks!
-Abhi

Re: [flask] advice on flask usage

From:
Smartboy
Date:
2012-10-27 @ 06:25
On Fri, Oct 26, 2012 at 11:00 PM, Abhishek Pratap <apratap@lbl.gov> wrote:

>
> On Fri, Oct 19, 2012 at 1:58 PM, pronoyc@gmail.com <pronoyc@gmail.com>wrote:
>
>> d3.js <http://d3js.org>
>>
>> Calculate and pass values to the page. Use JS library to generate them at
>> run time.
>>
>>
>> On Sat, Oct 20, 2012 at 2:20 AM, Abhishek Pratap <apratap@lbl.gov> wrote:
>>
>>> Hi Sean
>>>
>>> On Fri, Oct 19, 2012 at 1:31 PM, Sean Davis <sdavis2@mail.nih.gov>wrote:
>>>
>>>>
>>>>
>>>> On Fri, Oct 19, 2012 at 4:17 PM, Abhishek Pratap <apratap@lbl.gov>wrote:
>>>>
>>>>> Hi Guys
>>>>>
>>>>> This is my first email to the list. I have recently started using
>>>>> Flask which also happens to be my first attempt with web development so
>>>>> there are other obvious challenges too :).
>>>>>
>>>>> I have few basic questions and want to take your advice on how to best
>>>>> address them through flask.
>>>>>
>>>>> Background:
>>>>>
>>>>> 1. The main web page gets some data from user, the python code does
>>>>> some analysis in the background.
>>>>> 2. Now I have results which I want to display to the user. The results
>>>>> mainly are of 3 types.
>>>>>      2a. text
>>>>>      2b. plots
>>>>>      2c. Text to be displayed as tables.
>>>>>
>>>>> Questions:
>>>>>
>>>>> A. If I want to display multiple plots per page should I first create
>>>>> static images for each plot and then display them ? Is there a more slick
>>>>> way to display multiple plots per page without creating static images.  I
>>>>> did come across and example for doing this
>>>>> https://gist.github.com/1641344 but I am not sure how will the same
>>>>> logic work for multiple images on the same page.
>>>>>
>>>>
>>>> The web page from flask will include links to each image.  Those links
>>>> could be to static images or could be to flask routes that generated the
>>>> images on-the-fly.  The key is that the first page just includes links.
>>>>
>>>>
>>> >> If I understood this right, I dont think it will work for the way I
>>> want to display these plots. I want to redirect the user to a webpage which
>>> has multiple plots and not just links to the plots. Ideally I would like to
>>> render them using the approach shown on the github example listed ion my
>>> orig mail but not getting ideas to implement the same for multiple plots on
>>> the same web page.
>>>
>>>
>>>
>>>>
>>>>> B. I also want to display tables on the page and give use the
>>>>> capability to sort them on the page by any column. I am guessing I wud need
>>>>> some sort of JS code to do so but not sure what JS lib could integrate well
>>>>> with Flask and require less effort to implement.
>>>>>
>>>>>
>>>> You might look at jQuery datatables.  This doesn't change your flask
>>>> application at all, really, other than to include a few lines of javascript
>>>> in the page template.
>>>>
>>>
>>> >> Ok I will try to learn this
>>>
>>>>
>>>>
>>>>> C. Lastly if I am asking the user to enter a date on the web page, can
>>>>> I provide a calendar for the user to select a date. Again some JS library
>>>>> could help here but I dont have a lot of exp there.
>>>>>
>>>>>
>>>> I'm no expert, but learning a bit of jQuery and jQuery UI can go a long
>>>> way.  Others may have other favorites, though.  Again, on the flask side of
>>>> things, not much needs to change as the data will come back to flask as
>>>> post data from a form (generally).
>>>>
>>> >>  Could you recommend based on your experience any good source for
>>> quickly picking up on jquery.
>>>
>>>
>>>>
>>>> Sean
>>>>
>>>>
>>>
>>
>>
>> --
>> Regards,
>>
>> Pronoy Chopra
>> http://blog.pronoy.in <http://www.pronoy.in/about>/
>> http://www.twitter.com/pronoyc
>>
>
> Hi Guys
>
> I have a follow up question. In order to render plots by calling functions
> in the img src tag as suggested above(eg below)
>
>  <img src ="{{url_for('plot1')}}" >
>
> I need to pass computed values which were computed by the function called
> as a result of user form submission. This function in turns render the html
> template which makes calls to the plot methods ( <img src
> ="{{url_for('plot1')}}" >) . Each plot method needs to access that
> dictionary object computed earlier by the form response function to return
> a plot on the fly.
>
> In other words I would like to share a python objects between flask
> methods and if possible avoid exchanging them through the browser.
>
> Can I share objects on the server end itself  between the flask methods ?
>
> Thanks!
> -Abhi
>
>
>
You can't directly share the dictionary between the two methods since
you're actually translating to HTML first with this method, however you do
have an option. You can add keyword arguments to url_for as long as the
name matches the name of the arguments for plot1. If you serialize the
dictionary using either json (for simple types such as strings, lists,
ints, floats, and dicts) or pickle (more complex types), you can
unserialize it in plot1 and get your data back.

Smartboy

Re: [flask] advice on flask usage

From:
Abhishek Pratap
Date:
2012-10-27 @ 08:05
On Fri, Oct 26, 2012 at 11:25 PM, Smartboy <smartboyathome@gmail.com> wrote:

> On Fri, Oct 26, 2012 at 11:00 PM, Abhishek Pratap <apratap@lbl.gov> wrote:
>
>>
>> On Fri, Oct 19, 2012 at 1:58 PM, pronoyc@gmail.com <pronoyc@gmail.com>wrote:
>>
>>> d3.js <http://d3js.org>
>>>
>>> Calculate and pass values to the page. Use JS library to generate them
>>> at run time.
>>>
>>>
>>> On Sat, Oct 20, 2012 at 2:20 AM, Abhishek Pratap <apratap@lbl.gov>wrote:
>>>
>>>> Hi Sean
>>>>
>>>> On Fri, Oct 19, 2012 at 1:31 PM, Sean Davis <sdavis2@mail.nih.gov>wrote:
>>>>
>>>>>
>>>>>
>>>>> On Fri, Oct 19, 2012 at 4:17 PM, Abhishek Pratap <apratap@lbl.gov>wrote:
>>>>>
>>>>>> Hi Guys
>>>>>>
>>>>>> This is my first email to the list. I have recently started using
>>>>>> Flask which also happens to be my first attempt with web development so
>>>>>> there are other obvious challenges too :).
>>>>>>
>>>>>> I have few basic questions and want to take your advice on how to
>>>>>> best address them through flask.
>>>>>>
>>>>>> Background:
>>>>>>
>>>>>> 1. The main web page gets some data from user, the python code does
>>>>>> some analysis in the background.
>>>>>> 2. Now I have results which I want to display to the user. The
>>>>>> results mainly are of 3 types.
>>>>>>      2a. text
>>>>>>      2b. plots
>>>>>>      2c. Text to be displayed as tables.
>>>>>>
>>>>>> Questions:
>>>>>>
>>>>>> A. If I want to display multiple plots per page should I first create
>>>>>> static images for each plot and then display them ? Is there a more slick
>>>>>> way to display multiple plots per page without creating static images.  I
>>>>>> did come across and example for doing this
>>>>>> https://gist.github.com/1641344 but I am not sure how will the same
>>>>>> logic work for multiple images on the same page.
>>>>>>
>>>>>
>>>>> The web page from flask will include links to each image.  Those links
>>>>> could be to static images or could be to flask routes that generated the
>>>>> images on-the-fly.  The key is that the first page just includes links.
>>>>>
>>>>>
>>>> >> If I understood this right, I dont think it will work for the way I
>>>> want to display these plots. I want to redirect the user to a webpage which
>>>> has multiple plots and not just links to the plots. Ideally I would like to
>>>> render them using the approach shown on the github example listed ion my
>>>> orig mail but not getting ideas to implement the same for multiple plots on
>>>> the same web page.
>>>>
>>>>
>>>>
>>>>>
>>>>>> B. I also want to display tables on the page and give use the
>>>>>> capability to sort them on the page by any column. I am guessing I wud need
>>>>>> some sort of JS code to do so but not sure what JS lib could integrate well
>>>>>> with Flask and require less effort to implement.
>>>>>>
>>>>>>
>>>>> You might look at jQuery datatables.  This doesn't change your flask
>>>>> application at all, really, other than to include a few lines of javascript
>>>>> in the page template.
>>>>>
>>>>
>>>> >> Ok I will try to learn this
>>>>
>>>>>
>>>>>
>>>>>> C. Lastly if I am asking the user to enter a date on the web page,
>>>>>> can I provide a calendar for the user to select a date. Again some JS
>>>>>> library could help here but I dont have a lot of exp there.
>>>>>>
>>>>>>
>>>>> I'm no expert, but learning a bit of jQuery and jQuery UI can go a
>>>>> long way.  Others may have other favorites, though.  Again, on the flask
>>>>> side of things, not much needs to change as the data will come back to
>>>>> flask as post data from a form (generally).
>>>>>
>>>> >>  Could you recommend based on your experience any good source for
>>>> quickly picking up on jquery.
>>>>
>>>>
>>>>>
>>>>> Sean
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Regards,
>>>
>>> Pronoy Chopra
>>> http://blog.pronoy.in <http://www.pronoy.in/about>/
>>> http://www.twitter.com/pronoyc
>>>
>>
>> Hi Guys
>>
>> I have a follow up question. In order to render plots by calling
>> functions in the img src tag as suggested above(eg below)
>>
>>  <img src ="{{url_for('plot1')}}" >
>>
>> I need to pass computed values which were computed by the function called
>> as a result of user form submission. This function in turns render the html
>> template which makes calls to the plot methods ( <img src
>> ="{{url_for('plot1')}}" >) . Each plot method needs to access that
>> dictionary object computed earlier by the form response function to return
>> a plot on the fly.
>>
>> In other words I would like to share a python objects between flask
>> methods and if possible avoid exchanging them through the browser.
>>
>> Can I share objects on the server end itself  between the flask methods ?
>>
>> Thanks!
>> -Abhi
>>
>>
>>
> You can't directly share the dictionary between the two methods since
> you're actually translating to HTML first with this method, however you do
> have an option. You can add keyword arguments to url_for as long as the
> name matches the name of the arguments for plot1. If you serialize the
> dictionary using either json (for simple types such as strings, lists,
> ints, floats, and dicts) or pickle (more complex types), you can
> unserialize it in plot1 and get your data back.
>
> Smartboy
>



Ok I will try that.  Just wondering if it is possible to pass a plot object
to img src directly.

So for example the return response object from
https://gist.github.com/1641344, can that be passed to template like this

<img src = "{{response}}" />

It doesnt seem to be working for me. May be I am missing something or it is
not possible

-Abhi

Re: [flask] advice on flask usage

From:
Edd Robinson
Date:
2012-10-27 @ 08:50
Hi, 

On 27 Oct 2012, at 09:05, Abhishek Pratap <apratap@lbl.gov> wrote:

> Ok I will try that.  Just wondering if it is possible to pass a plot 
object to img src directly. 
> 
> So for example the return response object from 
https://gist.github.com/1641344, can that be passed to template like this
> 
> <img src = "{{response}}" />
> 
> It doesnt seem to be working for me. May be I am missing something or it
is not possible
> 
> -Abhi
> 

The img tag is used to link to an image at another resource, not to insert
one into a page.

Looking at your Gist I don't think plot takes any arguments from requests,
therefore the relevant figure can be already created and stored in your 
static asset folder. You could then include a link to it in the same why 
you would include a link to a CSS file or whatever.

Cheers,
Edd

Re: [flask] advice on flask usage

From:
Matt Conrad
Date:
2012-10-19 @ 20:45
On Fri, Oct 19, 2012 at 3:17 PM, Abhishek Pratap <apratap@lbl.gov> wrote:
> Hi Guys
>
> This is my first email to the list. [...]

Hi Abhi, mine too.  :)

I have just started with Flask myself, but your questions are not very
Flask-specific so I can offer my $0.02.

> A. If I want to display multiple plots per page should I first create static
> images for each plot and then display them?

Maybe, but I would try generating on the fly first.

> Is there a more slick way to
> display multiple plots per page without creating static images.  I did come
> across and example for doing this https://gist.github.com/1641344 but I am
> not sure how will the same logic work for multiple images on the same page.

For each image you make a request to the server. Instead of referring
to a location on the filesystem, you call your plot generation method
like the one in the gist. Rather than:

<img src="/images/plot1.png" />
<img src="/images/plot2.png" />

you would have

<img src="/plot/abcd/1234" />
<img src="/plot/defg/4567" />

so that the browser is hitting the "plot" method in Flask with
different parameters for each plot image.

> B. I also want to display tables on the page and give use the capability to
> sort them on the page by any column. I am guessing I wud need some sort of
> JS code to do so but not sure what JS lib could integrate well with Flask
> and require less effort to implement.

Like the other guy, I think DataTables is a good javascript-enhanced
table library. It is the easiest to use of those I've tried.

> C. Lastly if I am asking the user to enter a date on the web page, can I
> provide a calendar for the user to select a date. Again some JS library
> could help here but I dont have a lot of exp there.

I don't like calendar popups myself--I'd rather just use a textbox and
check/reformat values upon blur or pre-submit--but if you're going to
use one, I would go with the jquery datepicker, it is at least
commonly used.

You'll probably want to use jQuery as a general js library.

Good luck!

Matt