GSMEthesis commited on
Commit
2ff10f5
·
verified ·
1 Parent(s): 9764203

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
app.py CHANGED
@@ -775,7 +775,7 @@ body, .stApp {
775
  import streamlit as st
776
 
777
  def enhanced_likert_scale(question_data):
778
- """لیکرت اسکیل با دکمه‌های رادیویی Streamlit و بدون HTML"""
779
  question = question_data["question"]
780
  key = question_data["key"]
781
  scale = question_data["scale"]
@@ -789,29 +789,35 @@ def enhanced_likert_scale(question_data):
789
  st.markdown(f"<div style='text-align:right; font-weight:bold; margin-bottom:15px;'>{question}</div>",
790
  unsafe_allow_html=True)
791
 
792
- # ایجاد گزینه‌های لیکرت (1 تا scale)
793
- options = [str(i) for i in range(1, scale + 1)] # گزینه‌ها: "1", "2", ..., "scale"
794
-
795
- # نمایش برچسب‌ها و دکمه‌های رادیویی در یک ردیف
796
- col1, col2, col3 = st.columns([1, 3, 1])
797
- with col1:
798
  st.markdown(f"<span style='font-size:14px; font-weight:bold; color:#6a0dad;'>{labels[0]}</span>",
799
  unsafe_allow_html=True)
800
- with col2:
801
- value = st.radio(
802
- "",
803
- options,
804
- horizontal=True,
805
- key=f"{key}_radio",
806
- index=None, # هیچ گزینه‌ای به طور پیش‌فرض انتخاب نشده
807
- label_visibility="collapsed" # مخفی کردن لیبل پیش‌فرض
808
- )
809
- # ذخیره مقدار انتخاب‌شده در session_state
810
- if value is not None:
811
- st.session_state[key] = int(value)
812
- else:
813
- st.session_state[key] = 0
814
- with col3:
 
 
 
 
 
 
 
815
  st.markdown(f"<span style='font-size:14px; font-weight:bold; color:#6a0dad;'>{labels[1]}</span>",
816
  unsafe_allow_html=True)
817
 
 
775
  import streamlit as st
776
 
777
  def enhanced_likert_scale(question_data):
778
+ """لیکرت اسکیل با دکمه‌های رادیویی افقی در Streamlit"""
779
  question = question_data["question"]
780
  key = question_data["key"]
781
  scale = question_data["scale"]
 
789
  st.markdown(f"<div style='text-align:right; font-weight:bold; margin-bottom:15px;'>{question}</div>",
790
  unsafe_allow_html=True)
791
 
792
+ # ایجاد ستون‌ها برای برچسب‌ها و گزینه‌ها
793
+ col_label1, *option_cols, col_label2 = st.columns([1] + [1] * scale + [1])
794
+
795
+ # نمایش برچسب سمت راست
796
+ with col_label1:
 
797
  st.markdown(f"<span style='font-size:14px; font-weight:bold; color:#6a0dad;'>{labels[0]}</span>",
798
  unsafe_allow_html=True)
799
+
800
+ # نمایش دکمه‌های رادیویی به صورت افقی
801
+ with st.container():
802
+ options = [str(i) for i in range(1, scale + 1)] # گزینه‌ها: "1", "2", ..., "scale"
803
+ selected_value = st.session_state.get(key, 0)
804
+
805
+ for i, col in enumerate(option_cols, 1):
806
+ with col:
807
+ # استفاده از radio برای هر گزینه به صورت جداگانه
808
+ is_selected = selected_value == i
809
+ st.radio(
810
+ "",
811
+ [str(i)],
812
+ index=0 if is_selected else None,
813
+ key=f"{key}_radio_{i}",
814
+ label_visibility="collapsed",
815
+ horizontal=True,
816
+ on_change=lambda x=i: st.session_state.update({key: x})
817
+ )
818
+
819
+ # نمایش برچسب سمت چپ
820
+ with col_label2:
821
  st.markdown(f"<span style='font-size:14px; font-weight:bold; color:#6a0dad;'>{labels[1]}</span>",
822
  unsafe_allow_html=True)
823