def gen_inputs(input_count):
my_list = []
for i in range(input_count):
my_list.append(Input(id = f'a{i}', component_property='value'))
return my_list
above doesnt work
def test():
return [Input(id = f'a0', component_property='value'),Input(id = f'a1', component_property='value')]
above does work
edit: formatting
Hi @michaelfboxer welcome to the forum! Can you explain what
“does not work” means here? Did you get an error? On my machine
my_list = []
for i in range(5):
my_list.append(id=Input(f'a{i}', component_property='value'))
throws a TypeError
, but
my_list = []
for i in range(5):
my_list.append(Input(f'a{i}', 'value'))
works ok. Can you print my_list
inside the gen_inputs
callback if there is no error?
My bad on the does not work. After generating inputs this way, i can never get them to actually output to any of my div’s.
It is as if the id’s don’t register properly.
def create_inputs(self):
'''Return the dcc.Inputs of all possible filters.'''
input_list = []
l = arbitrary_list
for i in range(len(l)):
input_list.append(Input(component_id=f'{i}', component_property='value'))
print(input_list)
return input_list
Here is the output of the list,
print(input_list)
[<Input `0.value`>, <Input `1.value`>, <Input `2.value`>, <Input `3.value`>, <Input `4.value`>, <Input `5.value`>, <Input `6.value`>, <Input `7.value`>, <Input `8.value`>, <Input `9.value`>, <Input `10.value`>, <Input `11.value`>, <Input `12.value`>, <Input `13.value`>, <Input `14.value`>, <Input `15.value`>, <Input `16.value`>]
Here is the callback i am using.
@app.callback(Output(component_id='non-hidden', component_property='children'),
rclass.create_inputs())
def input_keys(*args):
return [*args]
Did you declare your components in the layout (with the same id) ?
@app.callback(Output(component_id='non-hidden', component_property='children'),
rclass.create_inputs())
#[Input(component_id = str(1), component_property='value'), Input(component_id = str(2),
#component_property='value'),Input(component_id = str(3), component_property='value')])
def input_keys(*args):
return [*args]
Yes the correct id’s are there.
The commented line does display properly, the rclass.create_inputs() whcih returns that list does not. This is when i got very confused.
‘’‘python
[Input(f’a{i}’, ‘value’) for i in range(10)]
ended uo working for me
‘’’