✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Combining DCC Upload with a DCC Interval element

Hello all,

I currently have a dashbord that lets a user use a dcc Upload object to browse for a file, stores the data in json, and then callbacks off that data to do a couple of plots. The underlying source data is updated periodically and I’d like to be able to use a dcc.interval element to automatically update the data based off of the file selection that the user completes in the dcc.Upload.

Right now I am able to get an initial file selection and plot created correctly but after the interval time is met the new data is not being pulled. I guess the question is can I re-trigger the dcc Upload function on the previously selected file without having to select the file again? I’ve verified that the interval element is working correctly outside of not pulling in the updated data element. Here is a simplified version of the code I am working with -

Thanks,

def parse_contents(contents,filename):
content_type, content_string = contents.split(’,’)

decoded = base64.b64decode(content_string)
if 'xls' in filename:
    # Assume that the user uploaded an excel file
    return pd.read_excel(io.BytesIO(decoded))

else:
return None

app.layout = html.Div(
dcc.Upload(id=‘upload’),
html.Div(id=‘main-data’, style={‘display’: ‘none’}), # hidden div
dcc.Interval(id=‘refresh-item’,interval=5601000),
dcc.Graph(id=‘fig’)
)

@app.callback(
Output(‘main-data’,‘children’),
[Input(‘refresh-item’,‘n_intervals’),
Input(‘upload-data’,‘contents’)],
[State(‘upload-data’,‘filename’)]
)

def displaySelection(n_elements,contents,filename):
if contents is None:
return

if int(n_elements)>-1: # in any case I want the data to be uploaded
    data = parse_contents(contents,filename)

    return data.to_json(orient='split')

Data is then pushed to a fig with other callbacks