Black Lives Matter. Please consider donating to Black Girls Code today.

Uploading a csv data and view that data in a table

Hi there ,I am currently working on dash , I have created three tabs in the first tab will display the uploaded data frame , but when I click on the second tab , the file which I uploaded in the first tab is missing , I need to use the same uploaded file in the second tab , and How can I do ,it can anyone of you guys can explain it to me , below is my code


this is first file

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output ,State
from a11 import app ,server
import EDA, Correlation_Matrix ,a23
#app = dash.Dash()
app.layout = html.Div(
[
html.Div(
[
dcc.Tabs(
id=“select_tabs”,
style={“height”: “20”, “verticalAlign”: “middle”},
children=[
dcc.Tab(label=“RAW-DATA”, value=“a23”),
dcc.Tab(label=“EDA”, value=“EDA_tab”),
dcc.Tab(label=“Correlation-Matrix”, value=“Matrix_tab”),
], value=“RAW_tab”

)

],
className=“row tabs_div”
),html.Div(id=“tab_content”, className=“row”, style={“margin”: “2% 3%”}),

html.Link(href=“https://use.fontawesome.com/releases/v5.2.0/css/all.css",rel="stylesheet”),

html.Link(href=“https://cdn.rawgit.com/plotly/dash-app-stylesheets/2d266c578d2a6e8850ebce48fdb52759b2aef506/stylesheet-oil-and-gas.css",rel="stylesheet”),

html.Link(href=“https://fonts.googleapis.com/css?family=Dosis”, rel=“stylesheet”),

html.Link(href=“https://fonts.googleapis.com/css?family=Open+Sans”, rel=“stylesheet”),

html.Link(href=“https://fonts.googleapis.com/css?family=Ubuntu”, rel=“stylesheet”),

html.Link(href=“https://cdn.rawgit.com/amadoukane96/8a8cfdac5d2cecad866952c52a70a50e/raw/cd5a9bf0b30856f4fc7e3812162c74bfc0ebe011/dash_crm.css”, rel=“stylesheet”)
],
className=“row”,
style={“margin”: “0%”},
)

@app.callback(Output(“tab_content”, “children”),[Input(“select_tabs”, “value”)])
def render_content(tab):
if tab == “a23”:
return a23.layout
elif tab == “EDA_tab”:
return EDA.layout
elif tab == “Matrix_tab”:
return Correlation_Matrix.layout
else:
return a23.layout

if name == “main”:
app.run_server(debug=True,port=8080)
#--------------------------------------------
#this is second file-----------------------------
import base64
import datetime
import io

import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table

import pandas as pd

from a11 import app ,server

#app = dash.Dash()

layout = html.Div([
dcc.Upload(
id=‘upload-data’,
children=html.Div([
'Drag and Drop or ',
html.A(‘Select Files’)
]),
style={
‘width’: ‘100%’,
‘height’: ‘60px’,
‘lineHeight’: ‘60px’,
‘borderWidth’: ‘1px’,
‘borderStyle’: ‘dashed’,
‘borderRadius’: ‘5px’,
‘textAlign’: ‘center’,
‘margin’: ‘10px’
},
# Allow multiple files to be uploaded
multiple=True
),
html.Div(id=‘output-data-upload’),
])

def parse_contents(contents, filename, date):
content_type, content_string = contents.split(’,’)

decoded = base64.b64decode(content_string)
try:
if ‘csv’ in filename:
# Assume that the user uploaded a CSV file
df = pd.read_csv(
io.StringIO(decoded.decode(‘utf-8’)))
elif ‘xls’ in filename:
# Assume that the user uploaded an excel file
df = pd.read_excel(io.BytesIO(decoded))
except Exception as e:
print(e)
return html.Div([
‘There was an error processing this file.’
])

return html.Div([
html.H5(filename),
#html.H6(datetime.datetime.fromtimestamp(date)),

dash_table.DataTable(
data=df.to_dict(‘rows’),
columns=[{‘name’: i, ‘id’: i} for i in df.columns]
),

html.Hr(), # horizontal line

# For debugging, display the raw contents provided by the web browser
html.Div(‘Raw Content’),
html.Pre(contents[0:200] + ‘…’, style={
‘whiteSpace’: ‘pre-wrap’,
‘wordBreak’: ‘break-all’
})
])

@app.callback(Output(‘output-data-upload’, ‘children’),
[Input(‘upload-data’, ‘contents’)],
[State(‘upload-data’, ‘filename’),
State(‘upload-data’, ‘last_modified’)])
def update_output(list_of_contents, list_of_names, list_of_dates):
if list_of_contents is not None:
children = [
parse_contents(c, n, d) for c, n, d in
zip(list_of_contents, list_of_names, list_of_dates)]
return children

# if name == ‘main’:
# app.run_server(debug=True)

#--------------------------------this is third tab---------------------
from RAW_DATA import update_output, parse_contents
from a23 import *
from a11 import app
import pandas as pd
import base64
import io

layout = html.Div([

html.Br(),
html.H5(“DATA”),
html.Div(dte.DataTable(rows=[{}], id=‘table12’))

])

# def parse_contents(contents, filename):
# content_type, content_string = contents.split(’,’)

# decoded = base64.b64decode(content_string)
# try:
# if ‘csv’ in filename:
# # Assume that the user uploaded a CSV file
# df = pd.read_csv(
# io.StringIO(decoded.decode(‘utf-8’)), low_memory=False)
# elif ‘xls’ in filename:
# # Assume that the user uploaded an excel file
# df = pd.read_excel(io.BytesIO(decoded), low_memory=False)

# except Exception as e:
# print(e)
# return None

# return dff.append(df)

@app.callback(Output(‘table12’, ‘rows’),
[Input(‘upload-data’, ‘contents’),
Input(‘upload-data’, ‘filename’)])
def update_output(contents, filename):
if contents is not None:
dff = parse_contents(contents, filename)
if dff is not None:
return dff.to_dict(‘records’)
else:
return [{}]
else:
return [{}]

Now my question is how to make the file uploaded in the first tab remain as static when I click on second and third tab and return on the first tab
Q2:how to use the same uploaded file in the second tab