✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Progress of data loading

I’m new to dash and as my first application, I want to build something that retrieves data from Yahoo Finance with country and date input.

My question is, if there any way to observe the progress of data loading. I thought about something like counting the number of loops and devide it by the total number of loops to be done. That would give me the percentage of completion. However, this method would not work with @app.callback because I define a function after callback and the function returns only one object at the end. Any other way of doing it? Loading state is not helpful in this case.

Something like this:

@app.callback(Output('initial-dataframe', 'children'),
            [Input('country-button', 'n_clicks')],
            [State('country_picker','value'),
            State('my_date_picker','start_date'),
            State('my_date_picker','end_date')])

#The function defined below takes the arguments from Input and State above.
def retrieve_data(n_clicks, country,start_date,end_date):
     start = datetime.strptime(start_date[:10],'%Y-%m-%d')
     end = datetime.strptime(end_date[:10],'%Y-%m-%d')

     #path is a global variable for the country csv file path.
     raw_data = pd.read_csv(os.path.join(path,country))

     ticker_data = {}
     count = 0
     for tic in raw_data['ticker']:
         if len(ticker_data)==0:
             try:
                 ticker_data.update({tic: web.DataReader(tic, 'yahoo', start,end)['Adj Close']})
                 count = count +1
             except:
                 continue

     stock_dataframe =  pd.DataFrame(ticker_data)
     stock_dataframe_json = stock_dataframe.to_json()
     return stock_dataframe_json