0

I was able to print the value of the dropdown using a callback. Is there any way to put this value in a python variable?

Dash Dropdown Example

I want to use it (turkey) in an API endpoint.

1 Answer 1

1

If you have the value in a callback, then it already is a Python variable. I assume you did something similar to this?

@app.callback(
    Output('my-output', 'value')
    Inputs[('my-input', 'value')])
def callback_func(dropdown_value):
    print(dropdown_value)

You can use dropdown_value here in that function just like any other Python variable. It is limited to the scope of the function, but you could do things to make it accessible elsewhere, just like with other variables in functions. You could write it to a file, add it to a list or dict from some other context, and so on.

2
  • I managed to store the value to variable outside the function. However, once that is done, I want to run the entire script again, is there a way to do so? Commented May 30, 2020 at 5:01
  • What do you mean by run the script again? The Dash server should continue to run, and the callback will fire every time the dropdown value changes, allowing you to manipulate it each time.
    – coralvanda
    Commented May 30, 2020 at 19:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.