plumdog / flask_table

Because writing HTML is fiddly and all of your tables are basically the same

Home Page:http://flask-table.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Investigate better Pandas DataFrame integration

plumdog opened this issue · comments

Originally raised in #93, but I think there could be more to investigate here.

(Note: I am not a Pandas user, so any input from anyone who has ever used it would be great!)

A DataFrame broadly speaking looks a lot like a table, with columns and some data. And the pattern of "I have lots of data in a DataFrame, I want to throw it at a table and look at in a Flask app" seems like it could be pretty common.

It might well be that this comes in the form of more of a recipe (and put into examples/), than actual code in the package. A dependency on pandas would be bad, but something to make using it with pandas easier would be lovely.

Maybe a from_dataframe method could be implemented where we can take in a dataframe as a parameter and use duck typing to work with it without requiring a dependency on pandas itself. The method proposed in #93 looks like a good basis for a more robust implementation.

It might also be helpful to look into pandas' DataFrame.to_html implementation.

My Flask knowledge is a bit rusty, but I'm a user of pandas, so maybe I can take a shot at the implementation if there's no one else interested :)

This tutorial might give you a start. However, I am not sure that flask_table is necessary with Pandas. DataFrame.to_html seems to be pretty powerful since you can accomplish my goal of adding a column of radio buttons to a dataframe to make the rows selectable.

Update:

I can't believe I am just finding this but Pandas has provisional support for conditional formatting when rendering dataframes to html. Notice the "Extensibility" section in the documentation.

Closing, because it looks like the tools built into Pandas are probably the solution to this. Or possibly, write your own table, along the lines of #93 (comment).