Hi there,
I am failing to get the table updated via the dropdown, like whenever I change the dropdown value the table is not changing. I have set the dropdown to be multi and from the dropdown i am using a function to generate a dataframe, the dataframe will have varying number of rows based on the number of items selected in dropdown. How do I get a dynamic output which is changing based on the selected dropdown.
when I selected the single value it is updating the table. But, when I selected the multiple values it is showing an error for example: KeyError: â[(âSmall glassâ, âBig glassâ, âH (Height)â)] not in indexâ.
Here is my dropdown
dcc.Dropdown(id=âmy-dropdownâ,
options=[{âlabelâ: i, âvalueâ: i} for i in XX],
value= âBig glassâ,
multi = True), and here is my update function: @app.callback(Output(âtableâ, ârowsâ), [Input(âmy-dropdownâ, âvalueâ)])
def Update_Datatable(selected):
return(Function(XX[[selected]])).to_dict(ârecordsâ)
Does anyone have any ideas about this problem? Please help me. Thank you!
def update_table(value):
M= #define columns or empty dt
for i in XX:
if i in value:
M=pd.concat(current table and new values)
return M.to_dict('records')
Be sure to define the column names somewhere though. you may need a dummy within which to store the tables you need.
Cheers!
But the problem is when I selecting the multiple values(dataframe columns) in the dropdown it is considering the values as a single value and showing an error ***â[(âSmall glassâ, âBig glassâ, âH (Height)â)] not in indexâ.***.
When I select a value âSmall glassâ it is recognising it in column index of a dataframe and providing the results. But, when I try to add another column âBig glassâ it is not considering as a seperate column, it is combining both the columns as a single column and showing an error that it is not in the dataframe index.
My results should be to calculate results for each column(selecting the value in the dropdown) and getting the results by adding the other columns(one after another).
I got the results for each column individually and for all values when selected once. So please help me how to get the results by adding values one after another. Thank you once again for your reply!
yes, Thank you.
I understand your point. But I have to use another function to generate the results. return(Function(XX[[selected]])).to_dict(ârecordsâ). I am trying it but unable to find the way. Do you have any idea?