How to get access to a variable in another triggered_id block?

I want to use a variable inside another triggered_id like this:

if trigger_id == 'upload-data1':
    namia_mep_2.drop('index', axis=1, inplace=True)

if triggerd_id == 'upload-data2':
   result_mep_namia = namia_mep_2 - total_emb_namia

Hi @abdoo ,

it’s quite dificult to answer this with the information given. What if the trigger _id==‘upload-data’ has never been triggered? Does the namia_mep_2 still exist? I assume, it is not a global variable otherwise your quiestion would not arise.

In general, you can share information between callbacks, have a read here:

i read the documentation but I didn’t find what I am looking for, what I want is simply to make the variable namia_mep_2 available outside the it’s triggered_id Block .
No it is not a global variable, and I am just wondering if there is a way to make it available in the whole callback function

Hi @abdoo ,

I still do not understand the problem. Could you post the complete code of your callback function?

here i want to invoke namia_mep_2 variable inside the second triggered_id

def stock(n_clicks, mep_namia, mep_asmac, emb, sample, jsonified_cleaned_data):
  ## alert for upload file
  alert_success = dbc.Alert('Selected', color='success', style={'font-size': '16px', 'text-align': 'center', 'padding-top': '5px', 'padding-bottom': '5px'})
  alert_fail = dbc.Alert('Please Upload the right file!', color='danger', style={'font-size': '15px', 'text-align': 'center', 'padding-top': '5px', 'padding-bottom': '5px'})
  ## alert for download button
  btn_alert = dbc.Alert('must Upload all files!', duration=3000, color='danger', className='btn-download-stock', id='btn-alert-css')
  ## dataset stored in dcc.Store
  datasets = dataset

  trigger_id = ctx.triggered[0]["prop_id"].split(".")[0]
  if trigger_id == 'upload-data1':    
    ## ===================== MEP NAMIA ============================================================
    ## READ mep_namia file
    _ , content_string = mep_namia.split(',')
    decoded = base64.b64decode(content_string)
    mepNamia = pd.read_excel(io.BytesIO(decoded))
    ## drop unnamed cols
    mepNamia.drop(columns=['Date', 'Unnamed: 1','Unnamed: 10'], inplace=True)
    ## total Namia mep/2
    namia_mep_2 = np.floor(mepNamia.tail(1).astype('float')/2).astype('int')

    ## rename cols
    namia_mep_2.rename(columns={'03': 'T03', '04': 'T04', '05': 'T05', '06': 'T06', '07': 'T07' }, inplace=True)
    ## reset index
    ## drop index col
    namia_mep_2.drop('index', axis=1, inplace=True)

  elif trigger_id == 'upload-data2':
    ## READ emb file
    _ , content_string = emb.split(',')
    decoded = base64.b64decode(content_string)
    emb_namia = pd.read_excel(io.BytesIO(decoded), sheet_name='NAMIA')    

    ## drop date col
    emb_namia.drop(columns=['Date'], inplace=True)
    emb_namia.loc[len(emb_namia.index)] = emb_namia.sum(axis=0)
    ## save total emb namia
    total_emb_namia = emb_namia.loc[[len(emb_namia.index)-1]].astype('int').reset_index()
    ## drop index col
    total_emb_namia.drop('index', axis=1, inplace=True)
    ## READ namia_mep_2 FROM dcc.Store datasets
    datasets = json.loads(jsonified_cleaned_data)
    namia_mep_2 = pd.read_json(datasets['namia_mep_2'], orient='split')

    ## final result of mep NAMIA
    result_mep_namia = namia_mep_2 - total_emb_namia