title: Unable To Plot Graph From PostgreSQL Query Results In Dash App
body: <p>I am attempting to write a simple code to simply plot a bar graph of some fruit names in the x-axis vs corresponding sales units. The aim of this code is just to understand how to query postgres results from heroku hosted database through a dash app.</p>
  
  <p>Below is the code,</p>
  
  <pre><code>from dash import dash
  import dash_core_components as dcc
  import dash_html_components as html
  import plotly.graph_objs as go
  import psycopg2
  import os
  
  DATABASE_URL = os.environ['DATABASE_URL']
  conn = psycopg2.connect(DATABASE_URL, sslmode='require')
  cur = conn.cursor()
  cur.execute("SELECT fruits FROM pgrt_table")
  fruits1=cur.fetchall()
  #print(fruits1)
  cur.execute("SELECT sales FROM pgrt_table")
  sales1=cur.fetchall()
  
  
  app = dash.Dash()
  
  app.layout = html.Div(children=[
      html.H1(
          children='Hello Dash'
      ),
  
      html.Div(
          children='''Dash: A web application framework for Python.'''
      ),
  
      dcc.Graph(
          id='example-graph',
         figure=go.Figure(
              data=[
                  go.Bar(
                  x=fruits1, y=sales1, name='SF'),
                  #{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
              ],
  
              #'layout':{
              #    'title': 'Dash Data Visualization'
              #}
          )
      )
  ])
  
  if __name__ == '__main__':
      app.run_server(debug=True)
  </code></pre>
  
  <p>The output is below,</p>
  
  <p><a href="https://i.stack.imgur.com/PlRDg.jpg" rel="nofollow noreferrer">Output to the above code</a></p>
  
  <p>The corresponding output is just the axes with no bar graphs. The connection with the db is working since printing fruits1 or sales1 gives me the values from the columns in postgres. The only issue is the plotting.</p>
  
  <p>NOTE: This question has been heavily modified since the previous draft was extremely vague without any code to show for. </p>