Hi everyone,
I found a few examples in this forum on how to make the whole DataTable row highlighted when a cell is selected. But I am struggling to integrate that with an already-existing callback.
Here’s my code that works (no row selection function): xenosaga/app.py at master · perfectly-preserved-pie/xenosaga · GitHub
It just renders the tab with the Dash DataTable only.
And then here is the code that should highlight the selected row, but doesn’t work. It gives me
“A nonexistent object was used in an Input
of a Dash callback. The id of this object is datatable-interactivity
and the property is active_cell
. The string ids in the current layout are: [tabs, tab-content]”
and
"ID not found in layout
Attempting to connect a callback Input item to component:
“datatable-interactivity”
but no components with that id exist in the layout.
If you are assigning callbacks to components that are
generated by other callbacks (and therefore not in the
initial layout), you can suppress this exception by setting
suppress_callback_exceptions=True
.
This ID was used in the callback(s) for Output(s):
tab-content.children, datatable-interactivity.selected_row_indices"
The code that spawns this error is as follows:
...
style_data_conditional = [
{
"if": {"state": "active"},
"backgroundColor": "rgba(150, 180, 225, 0.2)",
"border": "1px solid blue",
},
{
"if": {"state": "selected"},
"backgroundColor": "rgba(0, 116, 217, .03)",
"border": "1px solid blue",
},
]
# Create the Dash DataTable for episode 3
ep3_table = dash_table.DataTable(
columns=[
{"name": i, "id": i} for i in ep3_df.columns
],
data=ep3_df.to_dict("records"),
tooltip_delay=0,
tooltip_duration=None,
id='datatable-interactivity',
filter_action="native",
filter_options={
'case': 'insensitive',
'placeholder_text': 'Type a string to search...'
},
sort_action="native",
style_data_conditional=style_data_conditional,
)
# Create the tab content
tab_1 = html.Div(children=[ep1_table])
tab_3 = html.Div(children=[ep3_table])
# Create the home page layout
app.layout = dbc.Container([
dbc.Row( # First row: title card
[
dbc.Col([title_card]),
]
),
dbc.Row( # Second row: tabs/tables
html.Div(
[
dbc.Col(
[
tabs,
html.Div(id="tab-content")
]
)
]
),
),
],
className = "dbc"
)
# Create the callback to update the tab content
@app.callback(
[Output("tab-content", "children"),
Output("datatable-interactivity", "selected_row_indices")],
[Input("tabs", "value"),
Input("datatable-interactivity", "active_cell")]
)
def render_content(tab, active_cell):
if tab == "ep1":
return tab_1, []
elif tab == "ep3":
if active_cell is not None:
return tab_3, [active_cell["row"]]
return tab_3, []
# Run the app
app.run_server(debug=True)
I know my callback is wrong, but I don’t understand how to include both tab rendering and row highlighting together…