how do I put the data table inside the def and make a callback for this datatable?
from this example:
from dash import Dash, dcc, html, Output, Input, dash_table
import dash_bootstrap_components as dbc
import plotly.express as px
import pandas as pd
https://www.kaggle.com/datasets/tsarina/mexico-city-airbnb?select=listings1.csv
df = pd.read_csv("https://raw.githubusercontent.com/Coding-with-Adam/Dash-by-Plotly/master/Other/Monterrey/airbnb.csv")
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = dbc.Container([
dbc.Row([
dbc.Col([
dcc.Markdown('#### Select columns'),
columns_input := dcc.Dropdown(df.columns, multi=True, value=["host_name","number_of_reviews"])
], width=6),
dbc.Col([
dcc.Markdown('#### Select number of rows'),
rows_input := dcc.Input(type='number', value=10, min=1, max=200)
], width=6)
]),
dbc.Row([
dbc.Col([
table_placeholder := html.Div()
], width=12)
])
])
@app.callback(
Output(table_placeholder, 'children'),
Input(columns_input, 'value'),
Input(rows_input, 'value')
)
def update_graph(cols, data_size):
print(cols)
print(data_size)
dff = df.loc[0:data_size, cols]
your_table= dash_table.DataTable(
id='your-table',
data=dff.to_dict('records')
)
return [your_table]
if __name__ == '__main__':
app.run_server(debug=True)