Variable update via callbacks


I am trying to build a dash app, in which i am reading a csv file and filtering it based on user inputs and showing the output in a dash datatable.
As the data in a few columns are very large, I am using tooltip_data to show the complete cell data,

The problem I am facing is to show the tooltip data I need to have to define a dataframe df outside the call back function which would be used by the tooltip_data,
if i am assigning a empty df, tooltips are not populating and if i am reading the complete csv in df then the tooltips that are coming are not correct.

Please help me figure out a way by which i can use update the df outside of the callback itself.
PFB the code snippet.

import dash
from dash import Dash
import dash_table
import pandas as pd
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc
external_stylesheets = ['']

app = dash.Dash(__name__,external_stylesheets=[dbc.themes.LUX])

# df = pd.read_csv("emails_updated.csv")

# df = df[['Date', 'updated_To', 'updated_From', 'Subject', 'Message_Body', 'sentiment']]

df = pd.DataFrame()

app.layout = html.Div([
                    "Select the Employee",
                                {'label': 'lay-k', 'value': 'lay-k'},
                                {'label': 'giron-d', 'value': 'giron-d'},
                                {'label': 'nemec-g', 'value': 'nemec-g'}
                    placeholder="Select an Employee",
                    style={'height': '34px', 'width': '14rem','font-size': "100%"},
        columns=[{'id': c, 'name': c} for c in df.columns],
            'overflow': 'hidden',
            'textOverflow': 'ellipsis',
            'maxWidth': 0,

                column: {'value': str(value), 'type': 'markdown'}
                for column, value in row.items()
            } for row in df.to_dict('rows')

@app.callback([Output('table', 'data'),
               Output('table', 'columns')],
                Input('folder_picker', 'value')]
def update_table(employee):
    df = pd.read_csv("emails_updated.csv")
    df = df[df['employee']==employee]
    df = df[['Date', 'updated_To', 'updated_From', 'Subject', 'Message_Body', 'sentiment']]
    return df.to_dict('records') , [{"name": i, "id": i} for i in df.columns]

if __name__ == "__main__":

@chriddyp : Can you please help me out here.
Thanks in advance :slight_smile:

Global variables should be avoided in Dash apps. Instead, you should share the data as described here,

Hi @Emil,
i can change the name of the dataframe in the callback function but its still not solving my main problem of updating the primary df outside of the callback which would be used in the tooltip_data.

Hi @bajaj454,
Did you succeed to find an answer to your problem ?
I have a similar problem so I would love to have some insights :slight_smile:
Thanks in advance