Black Lives Matter. Please consider donating to Black Girls Code today.

Where to put code to determine WHERE to read csv from?

So I need to read two csv files BUT I have to run code that selects the most recent one in a linux directory. Normally in Python I would simply put this code like this

 if __name__ == '__main__':

   latest_csv = get_latest_csv( the_csv_directory) 

   df_latest    = pd.read_csv( latest_csv )

BUT I am hitting a problem. IF I put this code in a DASH app ( which works FINE if I hard code a csv file name) then the code below does NOT see the df_latest for some reason. Where am I supposed to put the code to designate any criteria needed to select the csv files?

 html.Div([  
                                   dash_table.DataTable(
                                   id='datatable_id',
                                   columns=[{"name": i, "id": i} for i in df_latest.columns],
                                   data=df.to_dict('records'),

Hi @comicpilsen what happens exactly when you use this code? Could give a bit more details here?

Hi @Emmanuelle
again thank you for taking an interest. I want to spend more time on this topic as I think that I rushed to question before digging into the research more. I tried to figure out how to flag it for deletion but EVEN messed that up. Ho hum, thank you again.

BUT, in answer to your request for clarification.

normally, a python program, I put the defs at the top and call them below the main but in the DASH app I wrote the app = dash.Dash(name) seemed to negate calling the defs from below the main
again I will mess with this some more.