Posted also on https://stackoverflow.com/q/54770918/2146052 to widen audience.
In the following example, the first row should be selected by default. But this does not happen unless I remove the replacement of the table in table-div
or take out the backend pagination.
Any hints why this is happening?
import dash
from dash.dependencies import Input, Output, State
import dash_table
import dash_html_components as html
import dash_core_components as dcc
import pandas as pd
app = dash.Dash(__name__)
PAGE_SIZE = 5
def get_data():
df = pd.DataFrame(pd.util.testing.getTimeSeriesData())
return df
df = get_data()
def get_table():
table = dash_table.DataTable(
id='datatable-paging',
#data=df.to_dict('rows'),
columns=[
{"name": i, "id": i} for i in sorted(df.columns)
],
pagination_settings={
'current_page': 0,
'page_size': PAGE_SIZE
},
pagination_mode='be',
row_selectable="single",
selected_rows=[0],
)
return table
def get_layout():
layout = html.Div([
html.Button('submit', id='mybutton'),
html.Div([
get_table()
], id='table-div')
], id='layout-div')
return layout
app.layout = get_layout()
@app.callback(
Output('table-div', 'children'),
[
Input('mybutton', 'n_clicks'),
],
[
State('table-div', 'children'),
]
)
def update_table(n_clicks, tabledivchildren):
return tabledivchildren
#return [get_table()]
@app.callback(
Output('datatable-paging', 'data'),
[Input('datatable-paging', 'pagination_settings')])
def update_graph(pagination_settings):
return df.iloc[
pagination_settings['current_page']*pagination_settings['page_size']:
(pagination_settings['current_page'] + 1)*pagination_settings['page_size']
].to_dict('rows')
if __name__ == '__main__':
app.run_server(host='0.0.0.0', debug=True)