Thanks!! @jlfsjunior this is super useful.
I tried your second suggestion and (after a few changes in the code) was able to make it run.
import dash
import dash_table
from dash.dependencies import Output, Input
import dash_html_components as html
import pandas as pd
import dash_bootstrap_components as dbc
import json
from dash.exceptions import PreventUpdate
from dash_extensions import EventListener
df = pd.read_csv("https://git.io/Juf1t")
df["id"] = df.index
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
table = dash_table.DataTable(
id="tbl",
data=df.to_dict("records"),
columns=[{"name": i, "id": i} for i in df.columns],
)
listen_table = html.Div(
[
EventListener(
id="el",
events=[{"event": "dblclick", "props": ["srcElement.className", "srcElement.innerText"]}],
logging=True,
children=table,
)
]
)
app.layout = dbc.Container(
[
dbc.Label("Click a cell in the table:"),
listen_table,
dbc.Alert("Click the table", id="out"),
html.Div(id="event"),
]
)
@app.callback(Output("event", "children"), Input("el", "event"), Input("el", "n_events"))
def click_event(event, n_events):
# Check if the click is on the active cell.
if not event or "cell--selected" not in event["srcElement.className"]:
raise PreventUpdate
# Return the content of the cell.
return f"Cell content is {event['srcElement.innerText']}, number of double clicks {n_events}"
@app.callback(Output("out", "children"), Input("tbl", "active_cell"))
def update_graphs(active_cell):
return json.dumps(active_cell)
if __name__ == "__main__":
app.run_server(debug=True, port=7676)
However, this does not solve my initial issue: how can I trigger the display of another dataframe when the user clicks on a row? I am not sure how can I create these conditional click events: if click on row 1, then show (random) dataframe1, if click on row 2, then show (random) dataframe 2, etc.
Do you have any ideas?
Thanks!!