Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -772,10 +772,9 @@ body, .stApp {
|
|
| 772 |
""", unsafe_allow_html=True)
|
| 773 |
|
| 774 |
# ========== توابع اصلی ==========
|
| 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"]
|
|
@@ -786,25 +785,26 @@ def enhanced_likert_scale(question_data):
|
|
| 786 |
st.session_state[key] = 0
|
| 787 |
|
| 788 |
# نمایش سوال
|
| 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 |
-
|
|
|
|
|
|
|
| 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)]
|
| 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 |
"",
|
|
@@ -818,15 +818,15 @@ def enhanced_likert_scale(question_data):
|
|
| 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 |
|
| 824 |
# نمایش پاسخ انتخابشده
|
| 825 |
if st.session_state[key] != 0:
|
| 826 |
-
st.markdown(f"<p style='text-align:right; color:#6a0dad;'>پاسخ شما: {st.session_state[key]}</p>",
|
| 827 |
unsafe_allow_html=True)
|
| 828 |
else:
|
| 829 |
-
st.markdown(f"<p style='text-align:right; color:#6a0dad;'>پاسخ شما: هنوز انتخاب نشده</p>",
|
| 830 |
unsafe_allow_html=True)
|
| 831 |
|
| 832 |
# خط جداکننده بنفش
|
|
@@ -837,6 +837,13 @@ def enhanced_likert_scale(question_data):
|
|
| 837 |
height: 2px;
|
| 838 |
background: #6a0dad;
|
| 839 |
margin: 20px auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
}
|
| 841 |
</style>
|
| 842 |
<div class="likert-separator"></div>
|
|
|
|
| 772 |
""", unsafe_allow_html=True)
|
| 773 |
|
| 774 |
# ========== توابع اصلی ==========
|
|
|
|
| 775 |
|
| 776 |
def enhanced_likert_scale(question_data):
|
| 777 |
+
"""لیکرت اسکیل با دکمههای رادیویی افقی و مرکزی در Streamlit"""
|
| 778 |
question = question_data["question"]
|
| 779 |
key = question_data["key"]
|
| 780 |
scale = question_data["scale"]
|
|
|
|
| 785 |
st.session_state[key] = 0
|
| 786 |
|
| 787 |
# نمایش سوال
|
| 788 |
+
st.markdown(f"<div style='text-align:right; font-weight:bold; margin-bottom:15px; direction: rtl;'>{question}</div>",
|
| 789 |
unsafe_allow_html=True)
|
| 790 |
|
| 791 |
+
# تنظیم چیدمان مرکزی با ستونها
|
| 792 |
+
total_cols = scale + 2 # یک ستون برای هر نقطه + 2 ستون برای برچسبها
|
| 793 |
+
col_widths = [1] + [2] * scale + [1] # برچسبها باریکتر، نقاط پهنتر برای مرکزیت
|
| 794 |
+
col_label1, *option_cols, col_label2 = st.columns(col_widths)
|
| 795 |
|
| 796 |
# نمایش برچسب سمت راست
|
| 797 |
with col_label1:
|
| 798 |
+
st.markdown(f"<span style='font-size:14px; font-weight:bold; color:#6a0dad; direction: rtl;'>{labels[0]}</span>",
|
| 799 |
unsafe_allow_html=True)
|
| 800 |
|
| 801 |
+
# نمایش دکمههای رادیویی به صورت افقی و مرکزی
|
| 802 |
with st.container():
|
| 803 |
+
options = [str(i) for i in range(1, scale + 1)]
|
| 804 |
selected_value = st.session_state.get(key, 0)
|
| 805 |
|
| 806 |
for i, col in enumerate(option_cols, 1):
|
| 807 |
with col:
|
|
|
|
| 808 |
is_selected = selected_value == i
|
| 809 |
st.radio(
|
| 810 |
"",
|
|
|
|
| 818 |
|
| 819 |
# نمایش برچسب سمت چپ
|
| 820 |
with col_label2:
|
| 821 |
+
st.markdown(f"<span style='font-size:14px; font-weight:bold; color:#6a0dad; direction: rtl;'>{labels[1]}</span>",
|
| 822 |
unsafe_allow_html=True)
|
| 823 |
|
| 824 |
# نمایش پاسخ انتخابشده
|
| 825 |
if st.session_state[key] != 0:
|
| 826 |
+
st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl;'>پاسخ شما: {st.session_state[key]}</p>",
|
| 827 |
unsafe_allow_html=True)
|
| 828 |
else:
|
| 829 |
+
st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl;'>پاسخ شما: هنوز انتخاب نشده</p>",
|
| 830 |
unsafe_allow_html=True)
|
| 831 |
|
| 832 |
# خط جداکننده بنفش
|
|
|
|
| 837 |
height: 2px;
|
| 838 |
background: #6a0dad;
|
| 839 |
margin: 20px auto;
|
| 840 |
+
direction: rtl;
|
| 841 |
+
}
|
| 842 |
+
/* اطمینان از مرکزیت در تمام دستگاهها */
|
| 843 |
+
@media (max-width: 768px) {
|
| 844 |
+
.likert-separator {
|
| 845 |
+
width: 90%;
|
| 846 |
+
}
|
| 847 |
}
|
| 848 |
</style>
|
| 849 |
<div class="likert-separator"></div>
|