sbsmapper / pages /chapter_index.py
georad's picture
Update pages/chapter_index.py
fe8d957 verified
raw
history blame
1.75 kB
import streamlit as st
import pandas as pd
for k, v in st.session_state.items():
st.session_state[k] = v
#st.title("📘SBS mapper")
st.title("📘Map internal description to SBS codes V2.0")
#st.header("Map internal descriptions to SBS codes V2.0")
st.subheader("Select specific Chapter for quicker results")
st.subheader("Demo currently limited to Chapter 20: Imaging services; (Work in progress)")
df_chapters = pd.read_csv("SBS_V2_Chapter_Index.csv")
df_chapters.iloc[25] = {"Chapter": 26, "Chapter title": "ALL CHAPTERS (will take more time)", "Blocks": "Total", "No. Codes": 10081}
def dataframe_with_selections(df_chapters: pd.DataFrame, init_value: bool = False) -> pd.DataFrame:
df_with_selections = df_chapters.copy()
df_with_selections.insert(0, "Select", init_value)
# Get dataframe row-selections from user with st.data_editor
edited_df = st.data_editor(
df_with_selections,
hide_index=True,
column_config={"Select": st.column_config.CheckboxColumn(required=True)},
disabled=df_chapters.columns,
)
# Filter the dataframe using the temporary column, then drop the column
selected_rows = edited_df[edited_df.Select]
return selected_rows.drop('Select', axis=1)
if "selected_chapters" not in st.session_state:
st.session_state['selected_chapters'] = []
selected_chapters_list = st.session_state.selected_chapters
selected_chapters = dataframe_with_selections(df_chapters)
st.write("Your selection:")
st.write(selected_chapters)
#selected_chapters_listdisplay = selected_chapters.iloc[:,0].tolist()
#st.write("SELECTED CHAPTERS: ", selected_chapters_listdisplay)
if selected_chapters is not None:
st.session_state.selected_chapters = selected_chapters_list