Hi @adamschroeder ,
Thank you for reply!
Let me explain with a sample webapp:
import plotly.express as px
import dataiku
import dash_bootstrap_components as dbc
import dash
import logging
import datetime
import pandas as pd
from dash.dependencies import Input, Output, State
from dash import dcc, dash_table,callback, html #, Input, Output
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
import datetime
import numpy as np
from flask import request
import os
import json
import plotly.graph_objects as go
from collections import OrderedDict
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Tabs(id="tabs-group", value='list1', children=[
dcc.Tab(label='first', value='list1'),
dcc.Tab(label='second', value='list2'),
dcc.Tab(label='tips', value='tips')
],
style= { 'width':'300px','height':'50px'}),
html.Div(id='tabs-content')
])
def build_content1():
df = pd.DataFrame(OrderedDict([
('climate', ['Sunny', 'Snowy', 'Sunny', 'Rainy','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o']),
('temperature', [13, 43, 50, 30,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]),
('city', ['NYC', 'Montreal', 'Miami', 'NYC','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'])
]))
cont = html.Div([
html.H5("datatable", style={"display": "inline-block","marginLeft":"10px"}),
dash_table.DataTable(
id='table-dropdown1',
data=df.to_dict('records'), #the contents of the table
columns=[
{'id': 'feedback', 'name': 'feedback', 'presentation':'input'},
{'id': 'climate', 'name': 'climate', 'presentation': 'dropdown'},
{'id': 'temperature', 'name': 'temperature'},
{'id': 'city', 'name': 'city', 'presentation': 'dropdown'},
],
editable=True,
persistence = True,
is_focused = True,
persisted_props=["page_current",'data'],
filter_action="native",
sort_action="native",
sort_mode="multi",
page_size= 200,
style_header={
'fontWeight': 'bold',
'height': 'auto', 'whiteSpace': 'normal',
'backgroundColor': '#FFF8DC',
'position': 'sticky', 'top':'-2px',
'zIndex' : 300,
'height': '100px'
},
style_data = { 'height': 'auto','whiteSpace': 'normal'},
style_table ={
'height': '400px', 'overflowY': 'auto', 'overflowX': 'auto',
'paddingTop': '0px'
},
dropdown={ #dictionary of keys that represent column IDs,
'climate': { #its values are 'options' and 'clearable'
'options': [ #'options' represents all rows' data under that column
{'label': i, 'value': i}
for i in df['climate'].unique()
],
'clearable':True
},
'city': {
'options':[
{'label': 'NYC', 'value': 'NYC'},
{'label': 'Miami', 'value': 'Miami'},
{'label': 'Montreal', 'value': 'Montreal'}
],
'clearable':False
}
}
)
])
return cont
def build_content2():
df = pd.DataFrame(OrderedDict([
('climate', ['Sunny', 'Snowy', 'Sunny', 'Rainy']),
('temperature', [13, 43, 50, 30]),
('city', ['NYC', 'Montreal', 'Miami', 'NYC'])
]))
cont = html.Div([
dash_table.DataTable(
id='table-dropdown2',
data=df.to_dict('records'), #the contents of the table
columns=[
{'id': 'feedback', 'name': 'feedback', 'presentation':'input'},
{'id': 'climate', 'name': 'climate', 'presentation': 'dropdown'},
{'id': 'temperature', 'name': 'temperature'},
{'id': 'city', 'name': 'city', 'presentation': 'dropdown'},
],
editable=True,
dropdown={ #dictionary of keys that represent column IDs,
'climate': { #its values are 'options' and 'clearable'
'options': [ #'options' represents all rows' data under that column
{'label': i, 'value': i}
for i in df['climate'].unique()
],
'clearable':True
},
'city': {
'options':[
{'label': 'NYC', 'value': 'NYC'},
{'label': 'Miami', 'value': 'Miami'},
{'label': 'Montreal', 'value': 'Montreal'}
],
'clearable':False
}
}
)
])
return cont
def build_tips_tricks():
cont = html.Div([
html.Br(), html.Br(),
html.H4(
"1."),
html.H4(
"2. "),
html.H4("3. ."),
html.H4(
"4..")
])
return cont
@app.callback(
Output('tabs-content', 'children'),
Output('tabs-group', 'value'),
Input('tabs-group', 'value')
)
def render_content(tab):
if tab == 'list1':
cont = build_content1()
return cont,tab
elif tab == 'tips':
cont = build_tips_tricks()
return cont, tab
elif tab == 'list2':
cont = build_content2()
return cont, tab
if __name__ == '__main__':
app.run_server(debug=True)
On the “first” tab When I select a sample temperature while scrolling down to 12, go to ‘second’ tab and revisit ‘first’ tab, then I have lost the state of datatable i.e if I need to check the row with temperature 12, then I have to scroll down again.
Is there any way we can freeze the ‘first tab’ when we click a particular cell and change tab?