Dropdown timestamp missing?

My callback function has three inputs:

  • two buttons
  • a dropdown menu

Based on these inputs a dash table is updated

I need to know which input is triggered, for the buttons I can use the timestamp value to figure out which one is pressed. However, for the dropdown, this timestamp is not available (could not find anything in the docs). Does anybody know a workaround for my problem?

I need to rewrite this function to also include the dropdown:

def get_most_recent_button_clicked(button_create, button_delete):
Note this temp fix till Plotly releases the version where they implement the callback context
link to the git: https://github.com/plotly/dash/pull/608
This functions determines which button was pressed based on the timestamp
:param button_create: last timestamp when the create button was pressed
:param button_delete: last timestamp when the delete button was pressed
:return: the last pressed button
if int(button_create) > int(button_delete):
return ‘button_create’
return ‘button_delete’

The bootstrap version of the dropdown does have it, I will be using this component :slight_smile:



Another WorkAround I use, if you need to play with the “Options” property present in Dcc.Dropdown, is to put this drop down in another Div and get the timestamp on that div.

An example :

html.Div(children = [
		id = 'dropdown-tracking-site-for-table',
		options = [{'label' : site, 'value' : site} for site in session['list_of_sites']],
		placeholder = 'Choose your site'
	], id = 'div-dropdown-timestamp', n_clicks_timestamp = 1)

And then in the callback (a bit tricky since it is in a datatable) :

		Output('table-tracking', 'data'),
		[Input('button-add-rows', 'n_clicks'),
    	Input('dropdown-tracking-site-for-table', 'value')],
		[State('table-tracking', 'data'),
		 State('table-tracking', 'columns'),
		 State('button-add-rows', 'n_clicks_timestamp'),
		 State('div-dropdown-timestamp', 'n_clicks_timestamp')])

	def add_row(n_clicks, value_dropdown, rows, columns, tp_button, tp_dropdown):
		if n_clicks is None and value_dropdown is None : 
			raise PreventUpdate()
		elif int(tp_button) > int(tp_dropdown) :
			rows.append({c['id'] : '' for c in columns})
			return rows
		elif int(tp_button) < int(tp_dropdown) :
			new_rows = rows
			for row in new_rows :
				row['SITE'] = str(value_dropdown)
			return new_rows 


1 Like