Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -37,21 +37,37 @@ df = get_data()
37
  # Streamlit UI
38
  st.title("🌍 CGD Survey Explorer (Live DB)")
39
 
40
- st.sidebar.header("πŸ”Ž Filter Questions")
41
- selected_country = st.sidebar.selectbox("Select Country", sorted(df["country"].unique()))
42
- selected_year = st.sidebar.selectbox("Select Year", sorted(df["year"].unique()))
 
 
 
 
43
  keyword = st.sidebar.text_input("Keyword Search", "")
44
 
45
- # Filtered data
46
  filtered = df[
47
- (df["country"] == selected_country) &
48
- (df["year"] == selected_year) &
49
  (df["question_text"].str.contains(keyword, case=False, na=False))
50
  ]
51
 
52
- st.markdown(f"### Results for **{selected_country}** in **{selected_year}**")
53
- st.dataframe(filtered[["country", "question_text", "answer_text"]])
 
 
 
 
 
 
 
 
 
 
 
54
 
 
55
  if filtered.empty:
56
  st.info("No matching questions found.")
57
 
 
37
  # Streamlit UI
38
  st.title("🌍 CGD Survey Explorer (Live DB)")
39
 
40
+ # Multiselect filters (defaults = empty, shows all if none selected)
41
+ country_options = sorted(df["country"].dropna().unique())
42
+ year_options = sorted(df["year"].dropna().unique())
43
+
44
+ selected_countries = st.sidebar.multiselect("Select Country/Countries", country_options)
45
+ selected_years = st.sidebar.multiselect("Select Year(s)", year_options)
46
+
47
  keyword = st.sidebar.text_input("Keyword Search", "")
48
 
49
+ # Apply filters
50
  filtered = df[
51
+ (df["country"].isin(selected_countries) if selected_countries else True) &
52
+ (df["year"].isin(selected_years) if selected_years else True) &
53
  (df["question_text"].str.contains(keyword, case=False, na=False))
54
  ]
55
 
56
+ # Generate dynamic subheading
57
+ heading_parts = []
58
+ if selected_countries:
59
+ heading_parts.append("Countries: " + ", ".join(selected_countries))
60
+ if selected_years:
61
+ heading_parts.append("Years: " + ", ".join(map(str, selected_years)))
62
+ if heading_parts:
63
+ st.markdown("### Results for " + " | ".join(heading_parts))
64
+ else:
65
+ st.markdown("### Results for All Countries and Years")
66
+
67
+ # Display results including answer_text
68
+ st.dataframe(filtered[["country", "year", "question_text", "answer_text"]])
69
 
70
+ # Empty result message
71
  if filtered.empty:
72
  st.info("No matching questions found.")
73