title: Python Dash - Dynamic and Static input options in same callback function
body: <p>I need to write a call back function which will have a dynamic input component and a static input component. But putting them together is throwing error.</p>
  <p>This is what I have done so far -</p>
  <pre><code>@app.callback(
      [Output(&quot;new_list&quot;, &quot;children&quot;)],
      [
       #Static Input Component
       Input(&quot;clear&quot;, &quot;n_clicks&quot;),
       #Dynamic Input Component
       Input(str(i), &quot;value&quot;) for i in item_list[['item3','item2','item1']].stack().groupby(level=0).agg(' '.join)
       ],
  )
  ###########################################################
  ## Updated sample working code
  
  import dash
  import dash_html_components as html
  import dash_bootstrap_components as dbc
  from dash import callback_context
  from dash.dependencies import Input, Output, State
  import numpy as np
  import pandas as pd
  import dash_table as dt
  
  item1 = ['A','A','B','B']
  item2 = [&quot;W&quot;,&quot;X&quot;,&quot;Y&quot;,&quot;Z&quot;]
  item3 = [&quot;L&quot;,np.nan,'M','L']
  item_list = pd.DataFrame(list(zip(item1,item2,item3)),columns=[&quot;item1&quot;,&quot;item2&quot;,&quot;item3&quot;])
  
  cat_list = item_list.item1.unique()
  global itemlist
  itemlist = pd.DataFrame( columns = ['item','qty'])
  for item in item_list[['item3','item2','item1']].stack().groupby(level=0).agg(' '.join):
      itemlist.loc[len(itemlist)] = (item,0)
  
  def Add_item(data,data2):
      print(&quot;BILLING: Add_item()&quot;)
      item_list = dbc.Card(children = [
                          generate_item(data,data2),
                          dbc.Row([
                              dbc.Col([
                                  dbc.Button(
                                      html.H5(&quot;Cancel&quot;), id=&quot;cancel&quot;, className=&quot;ml-auto&quot;, color = &quot;danger&quot;
                                  )
                              ]),
                              dbc.Col([
                                  dbc.Button(
                                      html.H5(&quot;Clear&quot;), id=&quot;clear&quot;, className=&quot;ml-auto&quot;, color = &quot;info&quot;
                                  )
                              ]),
                          ],style = {&quot;width&quot;: &quot;71rem&quot;})
                   ],  
                  id=&quot;modal-body-newitem&quot;
                  )
      return item_list
  
  def generate_item(item_list,itemlist):
      buttons = html.Div(children =[
                             dbc.Row([
                                  dbc.Button(
                                      html.H5(str('+ ' + a)),
                                      id= str(a),
                                      className=&quot;mb-3&quot;,
                                      color=&quot;primary&quot;,
                                      block=True
                                  ),
                                  dbc.Collapse([
                                          dbc.Card([
                                                  dbc.Row([
                                                          dbc.Col([dbc.Button(html.H5(str('+ ' + b)),className=&quot;mb-3&quot;,color=&quot;info&quot;,block=True, disabled = True)],width = 10),
                                                          dbc.Col([dbc.Input(type=&quot;number&quot;, min=0, max=20, step=1,value = itemlist.loc[itemlist.item == b,'qty'],id = b )],width = 2)
                                                  ]) for b in item_list.loc[item_list.item1== a, ('item3','item2','item1')].stack().groupby(level=0).agg(' '.join).sort_values()
                                          #,dbc.Card(dbc.CardBody(str(&quot;This content is for &quot; + a)))
                                          ],body = True, style = {&quot;width&quot;: &quot;71rem&quot;, &quot;justify&quot;: &quot;centre&quot;, &quot;align&quot;: &quot;centre&quot;})
                                  ],id= str(&quot;collapse&quot; + a))        
                              ]) for a in item_list.item1.unique()
                 ])
      
      return buttons
  
  app = dash.Dash(__name__,external_stylesheets=[dbc.themes.CYBORG])
  app.config.suppress_callback_exceptions = True
  server = app.server
  
  app.title=&quot;Test&quot;
  
  app.layout = html.Div([
               dbc.Card(
              dbc.CardBody(
                  [
                      html.H5(&quot;New Item&quot;, className=&quot;card-title&quot;),
                      Add_item(item_list,itemlist),
                      html.Div(id = 'new_list')
                  ]
              )
          )
  ])
  
  
  #Item Ctegory List
  @app.callback(
      [Output(str(&quot;collapse&quot; + i), &quot;is_open&quot;) for i in cat_list],
      [Input(str(i), &quot;n_clicks&quot;) for i in cat_list]+
      [Input(&quot;cancel&quot;, &quot;n_clicks&quot;)])
  def toggle_collapse_category_box(*args):
      trigger = callback_context.triggered[0] 
      print(&quot;MYBIZZAPP:toggle_collapse_category_box:  Call - &quot;+str(callback_context.triggered))
      if not callback_context.triggered or trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0] == 'cancel':
          print('MYBIZZAPP:toggle_collapse_category_box: Not Triggered/Cancel')
          global isopn
          isopn = [False] * len(cat_list) 
      else:
          print('MYBIZZAPP:toggle_collapse_category_box: Triggered')
          for i in range(len(cat_list)):
              if cat_list[i] == trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0]:
                  isopn[i] = not isopn[i]
                  
      return isopn
  
  
  ### Clear item list
  @app.callback(
      [Output(str(i), &quot;value&quot;) for i in item_list[['item3','item2','item1']].stack().groupby(level=0).agg(' '.join)],
      [Input(&quot;cancel&quot;, &quot;n_clicks&quot;),
       Input(&quot;clear&quot;, &quot;n_clicks&quot;)])
  def clear_item_box(n2,n3):
      trigger = callback_context.triggered[0]
      print(&quot;MYBIZZAPP:clear_item_box:  Call - &quot;+str(callback_context.triggered))
      if trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0] == 'cancel':
          print(&quot;MYBIZZAPP:clear_item_box: cancel order&quot;)
          itemlist = pd.DataFrame( columns = ['item','qty'])
          for item in item_list[['item3','item2','item1']].stack().groupby(level=0).agg(' '.join):
              itemlist.loc[len(itemlist)] = (item,0)
      elif trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0] == 'clear':
          print(&quot;MYBIZZAPP:clear_item_box: clear order&quot;)
          
      return [0] * len(item_list)
      
  
  #Menu item list
  @app.callback(
      [Output(&quot;new_list&quot;, &quot;children&quot;)],
      [Input(str(i), &quot;value&quot;) for i in item_list[['item3','item2','item1']].stack().groupby(level=0).agg(' '.join)]+
      [Input(&quot;clear&quot;, &quot;n_clicks&quot;),
       Input(&quot;cancel&quot;, &quot;n_clicks&quot;)])
  def menu_item_list(*args):
      trigger = callback_context.triggered[0] 
      print(&quot;MYBIZZAPP:menu_item_list:  Call - &quot;+str(callback_context.triggered))
      print(trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0])
      if not callback_context.triggered :
          print('MYBIZZAPP:menu_item_list: Not Triggered')
          global itemlist
          itemlist = pd.DataFrame( columns = ['item','qty'])
          for item in item_list[['item3','item2','item1']].stack().groupby(level=0).agg(' '.join):
              itemlist.loc[len(itemlist)] = (item,0)
      else:
          print('MYBIZZAPP:menu_item_list: Triggered')
          itemlist.loc[itemlist.item == trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0],'qty'] = trigger[&quot;value&quot;]
      
      if trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0] == 'clear' or trigger[&quot;prop_id&quot;].split(&quot;.&quot;)[0] == 'clear':
          print('MYBIZZAPP:menu_item_list: Clear|Cancel')
          itemlist['qty'] = 0
          
          
      print('MYBIZZAPP:menu_item_list: Item List')
      print(itemlist)
      return ['Total items selected - ' + str(sum(itemlist.qty))]
      
  
  
  
  if __name__ == '__main__':
      app.run_server(debug=True)
  
  </code></pre>
  <p>If I do not mention the static input component, code works fine. But I need to have the static component as well.</p>
  <p>Overall problem that I am trying to work on is - I have dynamic input text boxes, if and when a value is entered in any of these boxes, that value needs to be accounted for and returned as a table. Also, there is a 'clear' button. If clicked, all values should be re-set to default pre-defined value.</p>
  <p>Thanks for your help in advance.</p>