Using dropdown input in an if statement to select correct dataframe

Hello all,

I have a dropdown item and two data files stored in csv format. I want to take the current dropdown selection and say something like

if selection == 'A':
  df = pd.read_csv('dataFileA')
  df = pd.read_csv('dataFileB')

How can I do this? Is this the right approach? Any other opinions are appreciated.


Hi @kaankorkmaz

You can use dropdown or directly RadioItems. In both cases the property to use as Input is value.

@Eduardo thank you, I understand your suggestion but unfortunately it doesn’t solve my problem.

What I’m trying to do is, access the value property of my dropdown Input from outside of the dash app. So ideally, I would export the value property as a string so that I can use it in an if statement as shown above.

1 Like

I do not understand what you ere trying to do. :woozy_face:
You can do this if statement directly in your callback.
Other alternative is write the value in a file, but always throughout a callback.

I’m assuming your csv files have a standardized file names. If so, you can simply do this without writing bunch of if-statements:

df = pd.read_csv(f’dataFile{selection}.csv’)