Pandas Dataframe display on a webpage

Ok, I have managed to get some very nice results by now combining the hints I got here. In the actual Python viewer I use

@app.route('/analysis/<filename>')
def analysis(filename):
    x = pd.DataFrame(np.random.randn(20, 5))
    return render_template("analysis.html", name=filename, data=x)

e.g. I send the complete dataframe to the html template. My html template is based on bootstrap. Hence I can simply write

{% extends "base.html" %}
{% block content %}
<h1>{{name}}</h1>
{{ data.to_html(classes="table table-striped") | safe}}
{% endblock %}

There are numerous other options with bootstrap, check out here: http://getbootstrap.com/css/#tables

Base.html is essentially copied from here http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xii-facelift

The next question is obviously how to plot such a frame. Anyone any experience with Bokeh?

Thank you both to Matt and Sean.

thomas


The following should work:

@app.route('/analysis/<filename>')
def analysis(filename):
    x = pd.DataFrame(np.random.randn(20, 5))
    return render_template("analysis.html", name=filename, data=x.to_html())
                                                                # ^^^^^^^^^

Check the documentation for additional options like CSS styling.

Additionally, you need to adjust your template like so:

{% extends "base.html" %}
{% block content %}
<h1>{{name}}</h1>
{{data | safe}}
{% endblock %}

in order to tell Jinja you're passing in markup. Thanks to @SeanVieira for the tip.