Greetings
I am trying to save multiple dataframes (or multiple pieces of data) to a one dcc.store
component and recall any given dataframe seperately. I have recreated a scenario (below), where on initial load of the app, I add data (names of columns of some dummy dataframes) to the dcc.store, then I have two buttons to selectively pick which dataframe’s columns I want to view. How would one go about doing this?? I have seen other forum posts (like this one) of this, but I am still confused on the use of "MATCH"
in the "index"
of a dcc
component? What is being matched, to recall the data you want? What would the callback look like for my code, to recall the the column names for d
or e
selectively?
from dash import Dash, dcc, html, Input, Output, State
import pandas as pd
d = pd.DataFrame({"one": [1.0, 2.0, 3.0, 4.0], "two": [4.0, 3.0, 2.0, 1.0]})
e = pd.DataFrame({"one": [5,6,7,8,9], "three": [9,8,7,6,5]})
app = Dash(__name__)
app.layout = html.Div([
dcc.Store(id = "something", storage_type = "local"),
html.Button("d", id = "d", n_clicks = 0),
html.Button("e", id = "e", n_clicks = 0),
html.Div(id = "output_columns", children = "columns", style = {"color": "white"})
])
#Upon loading of app, info (name of columns of 'd' and 'e' dataframes) saved to dcc.store
@app.callback(
Output('something', 'data'),
Input('d', 'n_clicks'),
Input('e', 'n_clicks')
)
def update_output(a, b):
if (a == 0 and b == 0):
return [d.columns, e.columns]
if __name__ == '__main__':
app.run_server(debug=True)