@AnnMarieW Suppose I have a DataFrame df
and Dictionary dict-obj
, can I store them in data
property of dcc.Store
like below?
from dash.dependencies import Input, Output, State
import pandas as pd
import dash
import dash_table
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from file1 import func_call
layout = html.Div([
# Plot map
dcc.Graph(id="map-graph"),
dash_table.DataTable(id="table"),
dcc.Input(id="space"),
dcc.Input(id="type"),
dbc.Button(id="btn"),
dcc.Store(id="c-store")
])
@application.callback(Output("space","value"),
[
Input("type","value")
]
)
def generate_df(type):
# Function returns a Pandas DataFrame Object
df = func_call(type)
space_val = df[df["col1"] == "type"]]
return space_val
# Store map-graph and data-table in dcc.Store component
@application.callback(Output("c-store","data"),
[
Input("map-graph","figure"),
Input("table","data"),
# Pandas DataFrame -- useful for stats calculation
Input("df","data"),
# Store Dictionary Object
Input("dict_obj","data"),
Input("space","value"),
Input("type","value"),
Input("button","n_clicks")
]
)
def c_store(map, table, df, dict_obj, space, type, n_clicks):
print("DataFrame", df)
# Store map-graph and data-table as dictionary.
if n_clicks:
return {
"map": map,
"table": table,
"info" : [{"type": type, "space": space}],
"data-frame": df,
"dict-obj": dict_obj
}