A dashboard, First part of this dashboard to display a table, 3columns: "PA Handler": st.column_config.TextColumn(required=True), "Type of Policy": st.column_config.TextColumn(required=True), "Mphasis": st.column_config.SelectboxColumn(options=["Y", "N"]) make up some entries Second part can help insert data into the table Second part of this dashboard: 2 tabs, one is create entry, the other one is modify entry in create entry tab: allow user to manually input the data, and they can decide enter one entry or many entries at once when user clicked submit button, it will show in First part table in modify entry, when user select one entry in First Part, then user clicked button "Modify", original entry will show, and user can make changes
To upload files, please first save the app
import streamlit as st
import pandas as pd
from datetime import datetime
# Initialize session state for data storage
if 'data' not in st.session_state:
# Initialize with some sample data
st.session_state.data = pd.DataFrame({
'PA Handler': ['John Smith', 'Mary Johnson', 'Robert Brown'],
'Type of Policy': ['Life Insurance', 'Health Insurance', 'Auto Insurance'],
'Mphasis': ['Y', 'N', 'Y']
})
if 'selected_index' not in st.session_state:
st.session_state.selected_index = None
st.title("Policy Management Dashboard")
# First part - Display Table
st.subheader("Current Entries")
table = st.data_editor(
st.session_state.data,
column_config={
"PA Handler": st.column_config.TextColumn(required=True),
"Type of Policy": st.column_config.TextColumn(required=True),
"Mphasis": st.column_config.SelectboxColumn(options=["Y", "N"])
},
hide_index=True,
key='table'
)
# Second part - Tabs for Create and Modify
tab1, tab2 = st.tabs(["Create Entry", "Modify Entry"])
with tab1:
st.subheader("Create New Entries")
num_entries = st.number_input("Number of entries to add", min_value=1, max_value=10, value=1)
entries = []
for i in range(num_entries):
st.markdown(f"#### Entry {i+1}")
col1, col2, col3 = st.columns(3)
with col1:
handler = st.text_input(f"PA Handler {i+1}", key=f"handler_{i}")
with col2:
policy_type = st.text_input(f"Type of Policy {i+1}", key=f"policy_{i}")
with col3:
mphasis = st.selectbox(f"Mphasis {i+1}", options=["Y", "N"], key=f"mphasis_{i}")
entries.append({"PA Handler": handler, "Type of Policy": policy_type, "Mphasis": mphasis})
if st.button("Submit New Entries"):
new_data = pd.DataFrame(entries)
# Only add entries where PA Handler and Type of Policy are not empty
valid_entries = new_data[
(new_data['PA Handler'].str.len() > 0) &
(new_data['Type of Policy'].str.len() > 0)
]
if not valid_entries.empty:
st.session_state.data = pd.concat([st.session_state.data, valid_entries], ignore_index=True)
st.success("New entries added successfully!")
st.rerun()
else:
st.error("Please fill in required fields (PA Handler and Type of Policy)")
with tab2:
st.subheader("Modify Existing Entry")
# Get selection from the table
if len(table['edited_rows']) > 0:
st.session_state.selected_index = list(table['edited_rows'].keys())[0]
if st.session_state.selected_index is not None:
selected_row = st.session_state.data.iloc[st.session_state.selected_index]
st.markdown("#### Edit Entry")
col1, col2, col3 = st.columns(3)
with col1:
modified_handler = st.text_input("PA Handler", value=selected_row['PA Handler'])
with col2:
modified_policy = st.text_input("Type of Policy", value=selected_row['Type of Policy'])
with col3:
modified_mphasis = st.selectbox("Mphasis", options=["Y", "N"], index=0 if selected_row['Mphasis'] == "Y" else 1)
if st.button("Save Changes"):
if modified_handler and modified_policy: # Check required fields
st.session_state.data.at[st.session_state.selected_index, 'PA Handler'] = modified_handler
st.session_state.data.at[st.session_state.selected_index, 'Type of Policy'] = modified_policy
st.session_state.data.at[st.session_state.selected_index, 'Mphasis'] = modified_mphasis
st.success("Changes saved successfully!")
st.session_state.selected_index = None
st.rerun()
else:
st.error("Please fill in required fields (PA Handler and Type of Policy)")
else:
st.info("Select an entry from the table above to modify it")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?