@app.callback(
Output('react-graph','figure'),
[Input('reg_col','value')]
)
def update_graph(reg_col_name):
print(reg_col_name)
cur.execute("SELECT fruits FROM react_table WHERE region = 'reg_col_name'")
fruits1=cur.fetchall()
fruits_val = [fruit[0] for fruit in fruits1]
cur.execute("SELECT sales FROM react_table WHERE region = 'reg_col_name'")
sales1=cur.fetchall()
sales_val = [sales[0] for sales in sales1]
print(sales_val)
clo = conn.rollback()
return {
'data': [go.Bar(
x=fruits_val, y=sales_val, name='SF'
)]
}
I have the following callback for my app. The input is the region name passed through reg_col_name. On printing reg_col_name I do get the input option selected and it works.
The problem arises when I try to use that same variable to query within the postgres db. on printing sales_val I should receive a list of sales numbers but the ouput is just []
The table looks something like this.
Region Fruits Sales
reg1 apple 67
reg1 banana 100
reg1 mango 38
reg1 pineapple 78
reg1 peach 60
reg1 watermelon63
reg2 apple 10
reg2 banana 64
reg2 mango 42
reg2 pineapple 16
reg2 peach 68
reg2 watermelon21
reg3 apple 7
reg3 banana 59
reg3 mango 72
reg3 pineapple 4
reg3 peach 96
reg3 watermelon63
reg4 apple 83
reg4 banana 32
reg4 mango 17
reg4 pineapple 20
reg4 peach 83
reg4 watermelon71
Could it be something to do with the improper usage of the rollback() function ?