Dict object -- Datatable issue

Hi,

I am trying to fill the dict object from sql and then display in datatable. I am able to get only one row to display in datatable but the records returned are more than 100 rows. It always displays the last record fetched from the cursor.

Any help is much appreciated!

Below is the code:

import psycopg2

import collections

import sys

import pprint

import datetime

import itertools

from bokeh.io import output_file, show

from bokeh.layouts import widgetbox

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import DataTable, DateFormatter, TableColumn,NumberFormatter,StringFormatter

from bokeh.plotting import curdoc

conn_string = “”

conn = psycopg2.connect(conn_string);

cursor = conn.cursor();

try:

cursor.execute('SELECT date,facility,sales from facility')

rows = cursor.fetchall()

except Exception, e:

print "not able to connect"

for row in rows:

data = (dict(

dates=[row[0]],

sales=[row[3]],

facility = [row[1]]

))

source = ColumnDataSource(data)

columns = [

TableColumn(field=“dates”, title=“Date”,formatter=DateFormatter()),

TableColumn(field=“facility”, title=“Facility”, formatter=StringFormatter(font_style=“bold”)),

#TableColumn(field=“sales”, title=“Sales”, formatter=NumberFormatter(format=“0”))

]

data_table = DataTable( source = source ,columns=columns, width=400, height=280)

cursor.close()

conn.close()

curdoc().add_root(data_table)

Thanks

Hi,

Any insights or help appreciated.

Thanks

···

On Monday, November 14, 2016 at 11:11:20 PM UTC-5, vs wrote:

Hi,

I am trying to fill the dict object from sql and then display in datatable. I am able to get only one row to display in datatable but the records returned are more than 100 rows. It always displays the last record fetched from the cursor.

Any help is much appreciated!

Below is the code:

import psycopg2

import collections

import sys

import pprint

import datetime

import itertools

from bokeh.io import output_file, show

from bokeh.layouts import widgetbox

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import DataTable, DateFormatter, TableColumn,NumberFormatter,StringFormatter

from bokeh.plotting import curdoc

conn_string = “”

conn = psycopg2.connect(conn_string);

cursor = conn.cursor();

try:

cursor.execute(‘SELECT date,facility,sales from facility’)

rows = cursor.fetchall()

except Exception, e:

print “not able to connect”

for row in rows:

data = (dict(

dates=[row[0]],

sales=[row[3]],

facility = [row[1]]

))

source = ColumnDataSource(data)

columns = [

TableColumn(field=“dates”, title=“Date”,formatter=DateFormatter()),

TableColumn(field=“facility”, title=“Facility”, formatter=StringFormatter(font_style=“bold”)),

#TableColumn(field=“sales”, title=“Sales”, formatter=NumberFormatter(format=“0”))

]

data_table = DataTable( source = source ,columns=columns, width=400, height=280)

cursor.close()

conn.close()

curdoc().add_root(data_table)

Thanks