Hello, I have a datable with a dropdown menu within a column of cells. I’m trying to trigger a callback when a user makes a selection from the dropdown menu. I’ve tried 'Input(‘datatable’, ‘dropdown’) and ‘active_cell’ with no luck. Any other ideas? Here is a simple reproduction of my problem
import dash
from dash import Dash, html, dash_table, callback_context
from dash.exceptions import PreventUpdate
from dash import Input, Output, State, Patch, ctx, html
app = Dash(__name__)
table_contents = ['DrugA', 'DrugB', 'DrugC']
app.layout = html.Div([
dash_table.DataTable(
id='datatable',
columns=[
{'name': 'Drug', 'id': 'drug'},
{'name': 'Delivery', 'id': 'delivery', 'presentation': 'dropdown'},
],
data=[
{'drug': name, 'delivery': 'Infusion pump' if name == 'DrugA' else 'Bolus'}
for name in table_contents
],
editable=True,
row_deletable=True,
dropdown={
'delivery': {
'options': [
{'label': 'Bolus', 'value': 'Bolus'},
{'label': 'Infusion pump', 'value': 'Infusion pump'},
{'label': 'Slow injection', 'value': 'Slow injection'}
],
},
},
),
html.Div(id='selected-delivery-output'), # Output element to display selected items
], className="dbc_light", style={'background-color': 'white'})
@app.callback(
Output('selected-delivery-output', 'children'),
[dash.dependencies.Input('datatable', 'dropdown')],
prevent_initial_call=True
)
def display_selected_delivery(dropdown):
print(dropdown)
return dash.no_update
if __name__ == '__main__':
app.run_server(debug=True)