TutteInstitute / datamapplot

Creating beautiful plots of data maps
MIT License
449 stars 29 forks source link

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

Closed Ibrokhimsadikov closed 2 months ago

Ibrokhimsadikov commented 3 months ago

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?

lmcinnes commented 3 months ago

No that isn’t possible in datamapplot. You would want our ThisNotThat library which can do that and has a number of prebuilt widgets to attach to selection callbacks

On Sun, Apr 7, 2024 at 3:20 AM Ibrokhimsadikov @.***> wrote:

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 Sample data

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) }) Dash app

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?

— Reply to this email directly, view it on GitHub https://github.com/TutteInstitute/datamapplot/issues/19, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC3IUBLPVQU35SWHZTTEVS3Y4DXTHAVCNFSM6AAAAABF3C5WE6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGIZDSNRQGU4DAMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>