Hi!
I have a big DataFrame with data and I would like to:
- select some rows with customized filtering settings
- save this filtered table into a hidden Div for further uses (display graphs, …)
- display the filtered table with dash_table.DataTable and its pagination settings
Problem: My DataFrame is big (more than 2500 rows) and when I would like to save the entire table as json into the hidden Div, it does not work. But when it is filtered to be ‘small enough’, everything works perfectly. What should I do ? Did someone had the same issue ?
I was thinking about changing the way I share my filtered table, either with a dcc.Store or with a save into a .txt file that is linked to the user IP address. Is this a good idea ?
Here is an example of code:
dff = get_data()
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
html.Div(id='filtered-tab', style={'display': 'none'}),
dcc.Dropdown(id="drop-example-filter",
options=[{'label': i, 'value': i} for i in liste_options],
multi=True,
value=[],
),
html.Button('Submit', id='button'),
dash_table.DataTable(
id='tab',
columns=[{"name": i, "id": i} for i in dff.columns],
pagination_settings={
'current_page': 0,
'page_size': 25
},
pagination_mode='be'
)
])
@app.callback(
Output('filtered-tab', 'children'),
[Input('button', 'n_clicks')],
[State('drop-example-filter', 'value')])
def update_filtered_tab(n_clicks, filter_value):
filtered_dff = filtering(dff, filter_value)
return filtered_dff.to_json(date_format='iso', orient='split')
@app.callback(
Output('tab', 'data'),
[Input('filtered-tab', 'children'),
Input('tab', 'pagination_settings')])
def update_filtered_tab(filtered_tab, pagination_settings):
filtered_dff = pd.read_json(filtered_tab, orient='split')
return filtered_dff.iloc[
pagination_settings['current_page']*pagination_settings['page_size']:
(pagination_settings['current_page'] + 1)*pagination_settings['page_size']
].to_dict('rows')