Black Lives Matter. Please consider donating to Black Girls Code today.

Radios in generated table, callbacks

I’m using this data:

data = {"domains": {}}
data["domains"][""] = {"status": "Editing"}
data["domains"][""] = {"status": "Disabled"}

This table generation function:

def generate_table(dataframe, max_rows=10):
	rows = []
	header = [html.Tr(children=[
		], id='header')]

	for domain,info in data["domains"].items():
		status = "Unregistered"
		if "status" in info:
			status = info["status"]
				html.Td( html.Strong(domain,style={'padding': pad})),
				html.Td( dcc.RadioItems(
						{'label': 'Unregistered', 'value': 'Unregistered'},
						{'label': 'Registered', 'value': 'Approval'},
						{'label': 'Editing', 'value': 'Editing'},
						{'label': 'Edited', 'value': 'Edited'},
						{'label': 'Disabled', 'value': 'Disabled'}
					], value=status, labelStyle = { 'display': 'inline-block', 'padding': pad}, style={'display': 'inline', 'width': '10%', 'padding': pad})),

	table = html.Table(header + rows, id="table")

	return table

And this layout:

app.layout = html.Div([
		],style={'columnCount': 1}),
	], style={'margin': '30px', 'columnCount': 1})

I’m trying to make it so changing the radio selection in a row updates that element’s status in the data.

I tried a few different methods, the latest one is having the callback argument be *inputs, and generating a list of inputs including both the radio elements themselves (to trigger the callback), and the row, in order to get the relevant data. But this feels very clunky, and it’s not letting me isolate which row’s radio was specifically clicked.


Anyone? Still haven’t figured this out properly.

I haven’t looked into your use case too deeply, but on first pass it sounds like this would be a good case for our new pattern matching callbacks:

Alternatively, use the DataTable and, instead of radio items, use the built-in dropdowns: