Hello everyone, 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’”
Example of me clicking on A and it should show me the Lat and Log on the map
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)
My code for the table:
dash_table.DataTable(
id='testtable',
columns=[{"name": i, "id": i,
'deletable': False,
'renamable': True
} for i in df.columns],
data=df.to_dict('records'),
page_current=0,
page_size=20,
page_action='native',
sort_action='native',
column_selectable="single",
sort_mode='multi',
style_table={'overflowX': '',
'maxHeight': '1500px'},
style_header={'backgroundColor': 'rgb(119, 184, 199)'},
style_cell={'backgroundColor': 'rgb(207,227,232)',
'color': 'black',
'whiteSpace': 'normal',
'height': 'auto',
'textAlign': 'left',
},
export_format='xlsx',
export_headers='display',
merge_duplicate_headers=True,
filter_action='native',
editable=True,
row_deletable=True,
sort_by=[]),
dcc.Graph(figure=fig3_6,id='selectgraph'),
My callback for this is
@app.callback(
Output('selectgraph', 'children'),
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 [fig3_6] if column in dff
]
Thank you for reading my code, any help would be appreciated!