TutteInstitute/datamapplot

Is it possible to add callbacks with lasso selection between datamaplot and table?

Ibrokhimsadikov opened this issue · 1 comments

I wanted to ask if it is possible to be able to apply lasso selection and on selection another table riw indexes are displayed:

I want something similar to this:

import dash
from dash import html
from dash import dcc
import dash_table
import plotly.express as px
from dash.dependencies import Input, Output


import pandas as pd
import numpy as np

np.random.seed(0)
df = pd.DataFrame({
    "X": np.random.rand(100),
    "Y": np.random.rand(100),
    "Z": np.random.choice(["A", "B", "C"], 100)
})


app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Graph(
        id='scatter-plot',
        figure=px.scatter(df, x='X', y='Y', color='Z')
    ),
    dash_table.DataTable(
        id='data-table',
        columns=[{"name": i, "id": i} for i in df.columns],
        data=df.to_dict('records')
    )
])

@app.callback(
    Output('data-table', 'data'),
    Input('scatter-plot', 'selectedData')
)
def update_data_table(selected_data):
    if selected_data is None:
        return df.to_dict('records')

    selected_points = [point['pointIndex'] for point in selected_data['points']]
    filtered_df = df.iloc[selected_points]
    
    return filtered_df.to_dict('records')

if __name__ == '__main__':
    app.run_server(debug=True)

`

Is it feasible ask?