I want to have a dropdown that does not leave out options after choosing them. So if in the example below I pick “1”, then I want to be able to pick that again (now the selection becomes 2,3,4,5 after picking 1). Is this possible?
Thanks in advanced!
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Dropdown(
options=[{'label':i, 'value':i} for i in range(0,5)],
value=[],
multi=True
)
])
if __name__ == '__main__':
app.run_server(debug=True)
If what you want is in a multi dropdown to have the possibility to select an element more than ones I think it is not allowed.
If you want to select one option in different moment and have the posibility to select it again you need to set multi option False or clear the value of the dropdown ones it is used.
Thank you for replying. The reason I am asking is because depending on the first selection in a dropdown, I need again the same amount of corresponding numbers with that. Now I tried this, but I am clueless on how to get back the output.
Here some example code. So if I pick 2 variables in the first dropdown, there are 2 options to be filled, if I pick 3, I get 3 options that need to be filled. However, how do I get those chosen options back? It stored in html.Div(id=‘amount-of-picks’).
import pandas as pd
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import dash
'''De data'''
url = 'https://raw.githubusercontent.com/SimonTeg/multiple_regressions/main/MMM_data.csv'
df = pd.read_csv(url, error_bad_lines=False)
variable_names = list(df.columns)
var_options = []
for var in list(df.columns):
var_options.append({'label': str(var), 'value': var})
app = dash.Dash()
layout = html.Div([
html.Br(),
html.H6("Response curve variables:", style={'color': 'white'}),
dcc.Dropdown(
id='response-curve',
options=var_options,
value=['tv','radio'],
multi=True
),
html.Br(),
html.Div(id='title-response-cuves'),
html.Div(id='amount-of-picks')
], className="dash-bootstrap")
app.layout = layout
@app.callback(
Output(component_id='amount-of-picks', component_property='children'),
[Input(component_id='response-curve', component_property='value')]
)
def update_output(input):
dropdowns = []
for var in input:
dropdowns.append(
dcc.Dropdown(
id='response-curve-shape-'+var,
options=[{'label':i, 'value':i} for i in range(0,100)],
value=[],
multi=True
)
)
return dropdowns
@app.callback(
Output(component_id='title-response-cuves', component_property='children'),
[Input(component_id='response-curve', component_property='value')]
)
def update_output(input):
variables = ""
for var in input:
variables = variables + var + ", "
if len(input)>0:
Title = "Shapes for " + variables[:-1]
else:
Title = ""
return html.H6(Title)
if __name__ == '__main__':
app.run_server(debug=True)
Hi @Eduardo and @adamschroeder, thank you for looking at my question. And sorry for not making it clear.
What I need is the values from the new dropdowns that appear. So for example, if I pick tv, radio, sales in the first dropdown, 3 other dropdowns appear. And in those dropdowns I fill in 1, 4, 5. I need to get those values (1, 4, 5) for my next graph with a @callback.
But since they are dynamical I have no idea how to get them. Although I do have the id’s of the 3 dropdown (id=‘response-curve-shape-’+var, var from [tv, radio, sales]).
One thing that I enjoy about answering other user’s question is a kind of satisfaction of getting new problems and try to find solutions.
In your case, trying to understand what your problem is, its a problem in itself that means I can have two different satisfactions here thank you about that
I think I have an idea about what your problem is (still not so sure ):
You are using the values that the user picks as part of the ‘¡d name’ of each new dropdown, and your problem is how to identify those names?
well if this is the issue you have two alternatives;
As the callback that bilds the new dropdowns allways will change the components of the Div ‘amount-of-picks’ if the first dropdown is changed, you can use the ‘value’ of the first dropdown to rebild the name of each dropdown in another callback-
Not use the value of the first dropdown as part of each new dropdown, instead you can add a correlative number, then you call each dropdown for its number.
I’m in Argentina, where the COVID issues are a bit weird since Easter (we have a lockdown since March 17), as an example to understand our leaders: the schools were closed the entire Year and nobody knows if will resume next March. But the worst part is that we reach the highest number of dead for population.
The economy are also a bit weird since decades and our Government are doing a very strong effort to worsen it.
Living in this context If we don’t add a bit of humor we are dead.
That sounds awful, people with political power are usually not the ones we wish to be in those positions. Hope it will improve soon, and YES to some humor!