Paul's Programming Notes     Archive     Feed     Github

Get Column and Row Labels In selectHandler - Google Charts / Visualization API

For a more complete example of using selectHandler, see this page:

My example below get the labels from the row and the columns. I used this to send the user to another link and drill-down.

// this is an example of a bar chart's selectHandler function
function selectHandler() {
var selection = chart.getSelection();
var item = selection[0];

if (item.row != null && item.column != null) {
var rowLabel = parseInt(data.getValue(item.row, 0));
var columnLabel = data.getColumnLabel(item.column);
}, 'select', selectHandler);

Ordered Post Data - Python Requests

Here's an example of how to send ordered data with python's Requests library, for when the order of your post request data matters:

import requests
from collections import OrderedDict

payload = OrderedDict([("username", "admin"), ("pwd", "password")]) # the order matters!
r ='', data=payload)
print r.text

Checkmark "column_formatters" - Flask-Admin

In your custom ModelView, you need to add the following lines:
from flask.ext.admin.model.template import macro
column_formatters = dict(your_column=macro('render_your_column'))
list_template = 'list.html'

In your custom list.html template, you need to add the following jinja2 code:
{% macro render_your_column(model, column) %}
{% if model.your_column%}<i class="icon-ok"></i>{% endif %}
{% endmacro %}

If your row has a value in "your_column", then it will show as a checkmark. You need to make a new macro for each column.


Flask-Migrate is exactly what I've been looking for when it comes to database migrations. When I create PHP applications with MVC frameworks, the changes in the database need to be done manually when the model is changed. Flask-Migrate handles changes to the database (like adding/removing columns) so your models reflect your database.

This is a big advantage Flask has over PHP frameworks.

Pip Not Working From Powershell

If you have strawberry perl installed, you may get one of these errors when you try to use pip from powershell:

  • Did not provide a command
  • Unknown or unsupported command 'install'
This is the result of a conflict between strawberry perl's pip and python's pip. You need to remove anything related to strawberry perl from your path environmental variable and ensure you have C:\Python27\Scripts and C:\Python27\Scripts in your environmental variables.

Tableau's Frustrating Licensing Program

Tableau's licensing program is crazy.

I was planning to use "Trusted Authentication" to share an embedded chart with lots of users (not all of whom have licenses). Some of those users will only look at the chart maybe once a year, and we can't justify buying them an entire license to look at a chart once.

This page says "everyone who visits the page must be a licensed user on Tableau Server":

If you want more details on how to implement Trusted Authentication using PHP, first visit the following folder on your server: C:\Program Files\Tableau\Tableau Server\8.1\extras\embedding\php

It has some sample code, but you need to install version 1.x of pecl_http to make it work. The guides for that are:

Possible Solution To Slow SQLalchemy + Flask Application

This stackoverflow thread talks about why you want to use scoped_session:

Basically, your web application isn't thread-safe if you're not using scoped_session. It's much better than having you application use a new thread for every instance.

An example of scoped_session in use is available here:

Hide Zero Value Points On Google Chart

I have a line chart which needed a series of points. I don't want points to show if the value is zero.

Here's my solution:

  • Set the series's lineWidth to zero and make the point larger than 0:
    series: {0: {lineWidth: 0, pointSize: 5}}
  • Make the viewWindow setting's min higher than 0 (to hide the 0 points):
    vAxis: { viewWindowMode:'explicit', viewWindow:{ min: 0.5 } },