简体   繁体   中英

Dash datatable active_cell

I am trying to make my table interactive with my Mapbox using active cell. In my data table, when I click on the cell it supposes to show me the signification points of the Lat and Log on the map. However, it shows me the error of

“TypeError: update_graphs() missing 1 required positional argument: 'active_cell'”

Heres my code for mapbox:

    import dash
    import dash_bootstrap_components as dbc
    import dash_core_components as dcc
    import dash_html_components as html
    import pandas as pd
    import dash_table
    from dash.dependencies import Input, Output, State
    from engine import session
    from model import Table1
    import plotly.express as px
    import plotly.graph_objects as go
    
    mapbox_access_token = "my token map"
    df = pd.read_sql(session.query(Table1).statement,session.bind)
    fig=go.Figure(go.Scattermapbox(
            lat=['1.11','1.22','1.33'],
            lon=['101.12','101.22','102.54'],
            mode='markers',
            marker=go.scattermapbox.Marker(
                size=10,
              color='rgb(255, 0, 0)'
            ),
            text=["1","2","3"]
        ))
    fig.update_layout(
        autosize=True,
        hovermode='closest',
        mapbox=dict(
            accesstoken=mapbox_access_token,
            bearing=0,
            center=dict(
                lat=1.222,
                lon=103.856
            ),
            pitch=0,
            zoom=2
        ),
    )
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True)

html.Div([dash_table.DataTable(
                    id='testtable',
                    columns=[{"name": i, "id": i,
                              'deletable': False,  
                              'renamable': True  
                              } for i in df.columns],
                    data=df.to_dict('records'),  
                    #details design of my table which is slighty long#
                    )]),
                dcc.Graph(figure=fig3_6,id='selectgraph'),

      @app.callback(
        Output('selectgraph', 'figure'),
        Input('testtable', 'active_cell'),
        Input('testtable', 'selected_row_ids'))
    def update_graphs(row_ids,selected_row_ids,active_cell):
        selected_id_set = set(selected_row_ids or [])
    
        if row_ids is None:
            dff = df3_6
            row_ids = df3_6['id']
        else:
            dff = df3_6.loc[row_ids]
    
        active_row_id = active_cell['row_id'] if active_cell else None
        colors = ['#FF69B4' if id == active_row_id
                  else '#7FDBFF' if id in selected_id_set
        else '#0074D9'
                  for id in row_ids]
        return [
            dcc.Graph(
                id=column + '--row-ids',
                figure=fig3_6,
                mode='markers',
                marker=go.scattermapbox.Marker(
                    size=2,
                color=colors,
                ))
        for column in ['long','lat'] if column in dff
     ]

Thank you for reading my code, any help would be appreciated: :)

If you have two inputs in the callback function, than the arguments of the inside function must be two. You have three arguments so it is not possible to retrieve the third. Try to rewrite the code with the function like this

def update_graphs(active_cell,selected_row_ids):

In the same order of the inputs, and then reorganize the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM