Updating the dash application while the app is running

I am working on the multi-page apps. I have the functionality of reading from the CSV file on page1 and then passing that information(option parameter) to create a dropdown menu. I also have a refresh button. So whenever I click on the refresh button the CSV file will be updated. However, when I refresh the entire page the dropdown values are not getting updated (Since it depends on the information from the CSV file). It works if I stop the program and start from the beginning.

Structure of program

import packages

read a CSV file stored in a folder

create a layout
 - refresh button
 - create a dropdown  (dcc.Dropdown()) (takes the option parameter, which depend on the csv data)

action

run the app
read data from csv file then
displays the dropdown let say
a.1212
b.3232

Click on the refresh button
so the CSV file is getting updated,
expected
a.1212
b.3232
c.3432
what I am getting
a.1212
b.3232

How can I update the dropdown once the CSV file is getting updated?

Hi dash_m,

since no code is available, i only can give some advices.

You can use callbacks to update your dropdowns:
I have done something in my project:

@app.callback(
Output(‘windmill’,‘options’),
[
Input(‘location’,‘value’)
]
)

def GetWindmills(location):
‘’’ Get the windmills based on the first dropdown. ‘’’
# check the location
data = Windmill.copy()
if str(location) == ‘1’:
# return all windmills
logging.info(“return all Windmills”)
return [
{‘label’:label,‘value’:value} for label, value in zip(data[‘WINDMILL’],data[‘WINDMILL_ID’])
]

else:
    # return those within selected location
    logging.info(f'return Windmills from {location}')
    return [
        {'label':label,'value':value} \
        for label, value in zip(data.loc[data['LOCATION'] == location].WINDMILL,\
        data.loc[data['LOCATION'] == location].WINDMILL_ID)
    ]

Dash also provides live update components. Find a good documentation with this link:

https://dash.plotly.com/live-updates

Regards

1 Like