Hi there, I’m having an issue using a for loop to load initial dataframes that are used in a callback whose output is a graph. The code looks something like:
from dash import Dash
import glob
import pandas as pd
app = Dash(__name__)
datapath = '~/user/project/data/'
dataframes = {}
for file in glob.glob(datapath + '*.csv'):
dataframes[file] = pd.read_csv(file)
static_data = 'a random string'
@app.callback(Output('plot', 'figure'), Input('dropdown', 'value'))
def update_graph(dropdown_value):
df = dataframes[dropdown_value]
#rest of the graph creation
It seems (based on print statements) that everything in the code preceding the callback, including the static_data definition, except the for loop that loads my data runs before the callback fires. This results in dataframes being an empty dict when attempting to define df. Any ideas on why this would be the case?