✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Selected rows are getting deselected when i navigate from one page to another page

kazam

Hi dash community!, here i have created a table in page 1 when i select few rows and move to next page the selected rows are deselected. i have tried few things like storing the selected_rows in dcc.Store(id=‘temp’,storage_type=‘session’) and feeding it back to table. But it didn’t work.

**app.py**

import dash
app = dash.Dash(name, suppress_callback_exceptions=True)
server = app.server

page1.py

import dash_html_components as html
import dash_table
import pandas as pd
import dash_bootstrap_components as dbc
import dash_core_components as dcc

fruits_df=pd.DataFrame(dict(
Fruits=["Mango","Orange","WaterMelon","Grapes"],
    Price=["2","2.36","1.2","3.2"]
))
layout=dbc.Col([html.Div([
            dash_table.DataTable(
            id='fruits_table',
            columns=[{"name": i, "id": i} for i in fruits_df.columns],
            data=fruits_df.to_dict('records'),
            page_current = 0,
            selected_rows=[],
            row_selectable="multi"),
            dcc.Link('Go To Page 2', href='/page2/'),
            dcc.Store(id='temp',storage_type='session'),
            ])
        ],width=5)

page2.py

import dash_html_components as html
import dash_core_components as dcc

layout=html.Div([
    html.H3('Page 2'),
    dcc.Link('Go To Page 1', href='/')
])

index.py

import dash_html_components as html
import dash_table
from dash import Dash
from app import app
from dash.dependencies import Output, Input

import page1
import page2


app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='content')
])


@app.callback(Output('content', 'children'),
              [Input('url', 'pathname')])
def display_page(pathname):
    print(pathname)
    if pathname == '/':
        return page1.layout
    elif pathname == '/page2/':
        return page2.layout
    else:
        return '404'

if __name__ == '__main__':
    app.run_server(debug=True)

I don’t have any experience in Dash, i don’t known whether I’m doing it properly or not.

So, Any ideas are highly appreciated.
Thanks !

The problem is fixed, its simple i forget to use the Persistence=True.