Hi @AnnMarieW
Here is the example, not really minimal though. What I want to achieve is to have dash_table rendered upon selection from dropdown. Current setup requires opening a modal first. The use-case of this is additional filtering in the modal but it has to be optional (no opening required to load the data).
from dash import Dash, html, Input, Output, State, dash_table
import dash_ag_grid as dag
import pandas as pd
import dash_bootstrap_components as dbc
import dash_core_components as dcc
app = Dash(__name__)
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")
grid = dag.AgGrid(
id="grid",
rowData=[],
columnDefs=[{"field": i, "id": i} for i in df.columns],
defaultColDef={"resizable": True, "sortable": True, "filter": True, "minWidth":125},
columnSize="sizeToFit",
getRowId="params.data.State"
)
app.layout = html.Div([
dcc.Dropdown(
id='dropdown',
options=[{'label': i, 'value': i} for i in df['State'].unique()],
value=None,
),
html.Div(id="quickstart-output"),
dbc.Button("Open Modal", id="modal-button", className="mb-3"),
dbc.Modal(
[
dbc.ModalHeader(dbc.ModalTitle("Test")),
dbc.ModalBody(grid, className="py-4"),
],
id="modal",
size="xl",
is_open=False,
),
dbc.Card(dbc.CardBody(id="df_output3")),
])
@app.callback(
Output("grid", "rowData"),
Input("dropdown", "value")
)
def update_output(selected_state):
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")
filtered_df = df[df['State'] == selected_state]
new_df = filtered_df
return new_df.to_dict("records")
@app.callback(
Output("df_output3", "children"),
Input("grid", "virtualRowData"),
prevent_initial_call=True
)
def prepare_tbl_data(rows):
#selected = [s["API"] for s in selected] if selected else []
if len(rows) > 0:
df_tbl = pd.DataFrame(rows)
new_table = dash_table.DataTable(
data=df_tbl.to_dict("records"),
columns=[{"name": i, "id": i} for i in df_tbl.columns],
style_header={'backgroundColor': 'rgb(44, 62, 80)', 'color': 'white'}
)
return new_table
return None
@app.callback(
Output("modal", "is_open"),
Input("modal-button", "n_clicks"),
State("modal", "is_open"),
)
def toggle_modal(n1, is_open):
if n1:
return not is_open
return is_open
if __name__ == "__main__":
app.run_server(debug=True)