myshirk commited on
Commit
81d02b5
ยท
verified ยท
1 Parent(s): 18077e1

go back to prev filter

Browse files
Files changed (1) hide show
  1. app.py +16 -26
app.py CHANGED
@@ -38,30 +38,20 @@ df = get_data()
38
  st.title("๐ŸŒ CGD Survey Explorer (Live DB)")
39
 
40
  st.sidebar.header("๐Ÿ”Ž Filter Questions")
41
-
42
- # COUNTRY filter with "All" toggle
43
- all_countries = sorted(df["country"].dropna().unique())
44
- use_all_countries = st.sidebar.checkbox("Include All Countries", value=True)
45
-
46
- if use_all_countries:
47
- selected_countries = all_countries
48
- else:
49
- selected_countries = st.sidebar.multiselect("Select Countries", all_countries)
50
-
51
- # YEAR filter with "All" toggle
52
- all_years = sorted(df["year"].dropna().unique())
53
- use_all_years = st.sidebar.checkbox("Include All Years", value=True)
54
-
55
- if use_all_years:
56
- selected_years = all_years
57
- else:
58
- selected_years = st.sidebar.multiselect("Select Years", all_years)
59
-
60
- # Free-text keyword filter
61
- keyword = st.sidebar.text_input("Keyword Search (in question)", "")
62
-
63
- # Column selection
64
- all_columns = df.columns.tolist()
65
- default_columns = ["country", "year", "question_text", "answer_text"]
66
- selected_columns = st.sidebar.multiselect("Columns to Display", all_columns, default=default_columns)
67
 
 
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