I’ve added below an example to show my problem. It’s weirder than I thought. I added a callback that prints then returns the data in another div, to check if there is data. The data is printed but not returned.
’Normal example’:
# ----- IMPORTS
import dash
import dash_html_components as html
from dash.dependencies import Output, Input
import pandas as pd
import dash_table
# ----- DATA
data = {
'col 1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'col 2': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}
datatable = pd.DataFrame(data)
# ----- APP
app = dash.Dash(__name__)
app.layout = html.Div([
html.Button('click me', id='btn'),
html.Div(id='results'),
html.Div(id='mydata')
])
# ----- CALLBACK
@app.callback(
Output('results', 'children'),
[Input('btn', 'n_clicks')]
)
def create_datatable(n):
return html.Div([
dash_table.DataTable(
id='global-datatable',
columns=[{"name": i, "id": i} for i in datatable.columns],
data=datatable.to_dict("rows"),
pagination_mode='fe',
pagination_settings={
'current_page': 0,
'page_size': 5,
},
)
])
# ----- RUN
if __name__ == '__main__':
app.run_server(debug=True)
Example with weird callback:
import dash
import dash_html_components as html
from dash.dependencies import Output, Input
import pandas as pd
import dash_table
# ----- DATA
data = {
'col 1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'col 2': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}
datatable = pd.DataFrame(data)
# ----- APP
app = dash.Dash(__name__)
app.config['suppress_callback_exceptions'] = True
app.layout = html.Div([
html.Button('click me', id='btn'),
html.Div(id='results'),
html.Div(id='mydata')
])
# ----- CALLBACK
@app.callback(
Output('results', 'children'),
[Input('btn', 'n_clicks')]
)
def create_datatable(n):
return html.Div([
dash_table.DataTable(
id='global-datatable',
columns=[{"name": i, "id": i} for i in datatable.columns],
data=datatable.to_dict("rows"),
pagination_mode='fe',
pagination_settings={
'current_page': 0,
'page_size': 5,
},
)
])
@app.callback(
Output('mydata', 'children'),
[Input('global-datatable', 'data')]
)
def show_that_data_exists(data):
print(data)
return html.Div(data)
# ----- RUN
if __name__ == '__main__':
app.run_server(debug=True)