title: How to get the count from a dataframe from a Dash Callback
body: <p>I'd like to display the count of certain criteria inside a div in my dash layout based off callback selection from dropdown.</p>
  
  <p>I'm able to get the dropdown for the values in a pandas dataframe column, but I'm having trouble figuring out how to display the total count of the a selected element of the column.  </p>
  
  <p>For example, I've written a function in Jupyter notebook to get a count </p>
  
  <pre><code>def getCount(df, selected_org):
      totCount = df[df['ORGANIZATIONS'] == selected_org].AGENCY.count()
      return count
  
  selected_org = 'REGION 1'
  
  getCount(df, selected_org)
  </code></pre>
  
  <p>Which displays a value of: 3187</p>
  
  <p>This value is the result of my selected_org variable.  </p>
  
  <p>Now, I'd like to do the same thing in my dash layout based off the selection from dropdown. I used much of the code here to get started from Udemy course:  Interactive Python Dashboards with Plotly and Dash</p>
  
  <p>I start with my layout:</p>
  
  <pre><code>org_options = []
  for org in df['ORG_CODE_LEVEL_2_SHORT'].unique():
  org_options.append({'label': str(org), 'value': org})
  
  app.layout = html.Div(children=[
  
  html.Label('Select Org:'),
      dcc.Dropdown(id='org-dropdown', options=org_options, 
      value=df['ORG_CODE_LEVEL_2_SHORT'].min()),
  html.P(html.Div(id='container'))
  </code></pre>
  
  <p>Then my call back:</p>
  
  <pre><code>@app.callback(
      Output(component_id='container', component_property='children'), 
  [Input(component_id='org-dropdown', component_property='value')])
  def update_table(selected_org):
      filtered_org = df[df['ORG_CODE_LEVEL_2_SHORT'] == selected_org]
      return getCount(df, filtered_org)
  </code></pre>
  
  <p>And a function to generate the count:</p>
  
  <pre><code>def getCount(df, selected_org):
  
      totCount = df[df['ORG_CODE_LEVEL_2_SHORT'] == 
                 selected_org].AGENCY_INFO_5.count()
  
  return html.H2(totCount)
  </code></pre>
  
  <p>Which give me the following:</p>
  
  <p><a href="https://i.stack.imgur.com/9qjEX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9qjEX.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ya6Rb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ya6Rb.png" alt="enter image description here"></a></p>
  
  <p>But it isn't giving me the count.  Any help is appreciated.  </p>
  
  <p>Final complete program:</p>
  
  <pre><code>import os
  import glob
  import pandas as pd
  import numpy as np
  import dash
  import dash_core_components as dcc
  import dash_html_components as html
  from dash.dependencies import Input, Output
  
  app = dash.Dash()
  
  # DATA FROM EEPROFILE
  path = r'mydata'
  extension = 'xlsx'
  os.chdir(path)
  files = [i for i in glob.glob('*.{}'.format(extension))]
  latest_file = max(files, key=os.path.getctime)
  df = pd.DataFrame()
  eeprofi = pd.read_excel(latest_file, converters={'ORG_CODE_LEVEL_3': str})
  df = df.append(eeprofi)
  
  def getCount(df, selected_org):
  
      totCount = df[df['ORG_CODE_LEVEL_2_SHORT'] == selected_org].AGENCY_INFO_5.count()
  
      return html.H2(totCount)
  
  org_options = []
  for org in df['ORG_CODE_LEVEL_2_SHORT'].unique():
      org_options.append({'label': str(org), 'value': org})
  
  app.layout = html.Div(children=[
  
      html.Label('Select Org:'),
      dcc.Dropdown(id='org-dropdown', options=org_options, value=df['ORG_CODE_LEVEL_2_SHORT'].min()),
      html.P(html.Div(id='container'))
  
  ])
  
  @app.callback(
      Output(component_id='container', component_property='children'), [Input(component_id='org-dropdown', component_property='value')])
  def update_table(selected_org):
      filtered_org = df[df['ORG_CODE_LEVEL_2_SHORT'] == selected_org]
      return getCount(df, filtered_org)
  
  
  if __name__ == '__main__':
      app.run_server()
  </code></pre>