Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -774,7 +774,7 @@ body, .stApp {
|
|
| 774 |
|
| 775 |
# ========== توابع اصلی ==========
|
| 776 |
def enhanced_likert_scale(question_data):
|
| 777 |
-
"""لیکرت اسکیل با
|
| 778 |
question = question_data["question"]
|
| 779 |
key = question_data["key"]
|
| 780 |
scale = question_data["scale"]
|
|
@@ -788,42 +788,34 @@ def enhanced_likert_scale(question_data):
|
|
| 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 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
|
|
|
| 800 |
|
| 801 |
-
# ن
|
| 802 |
options = list(range(1, scale + 1))
|
| 803 |
-
|
| 804 |
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
unsafe_allow_html=True
|
| 819 |
-
)
|
| 820 |
-
if st.button("", key=button_key, help=f"Select value {value}", disabled=False):
|
| 821 |
-
st.session_state[key] = value
|
| 822 |
-
|
| 823 |
-
# نمایش برچسب سمت چپ
|
| 824 |
-
with cols[1]:
|
| 825 |
-
st.markdown(f"<div style='text-align:left; font-size:14px; font-weight:bold; color:#6a0dad; direction: rtl;'>{labels[1]}</div>",
|
| 826 |
-
unsafe_allow_html=True)
|
| 827 |
|
| 828 |
# نمایش پاسخ انتخابشده
|
| 829 |
if st.session_state[key] != 0:
|
|
@@ -833,37 +825,58 @@ def enhanced_likert_scale(question_data):
|
|
| 833 |
st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl;'>پاسخ شما: هنوز انتخاب نشده</p>",
|
| 834 |
unsafe_allow_html=True)
|
| 835 |
|
| 836 |
-
# خط جداکننده
|
| 837 |
-
st.markdown(
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
width: 80%;
|
| 841 |
-
height: 2px;
|
| 842 |
-
background: #6a0dad;
|
| 843 |
-
margin: 20px auto;
|
| 844 |
-
direction: rtl;
|
| 845 |
-
}
|
| 846 |
-
/* اجبار به چیدمان افقی در موبایل */
|
| 847 |
-
@media (max-width: 768px) {
|
| 848 |
.likert-separator {
|
| 849 |
-
width:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 850 |
}
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
|
|
|
|
|
|
|
|
|
| 858 |
}
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
return st.session_state.get(key)
|
| 869 |
|
|
|
|
| 774 |
|
| 775 |
# ========== توابع اصلی ==========
|
| 776 |
def enhanced_likert_scale(question_data):
|
| 777 |
+
"""لیکرت اسکیل با st.radio و استایل ساده"""
|
| 778 |
question = question_data["question"]
|
| 779 |
key = question_data["key"]
|
| 780 |
scale = question_data["scale"]
|
|
|
|
| 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 |
+
st.markdown(
|
| 793 |
+
f"""
|
| 794 |
+
<div style='display: flex; justify-content: space-between; max-width: 475px; margin: 0 auto; direction: rtl;'>
|
| 795 |
+
<span style='font-size: 14px; font-weight: bold; color: #6a0dad;'>{labels[0]}</span>
|
| 796 |
+
<span style='font-size: 14px; font-weight: bold; color: #6a0dad;'>{labels[1]}</span>
|
| 797 |
+
</div>
|
| 798 |
+
""",
|
| 799 |
+
unsafe_allow_html=True
|
| 800 |
+
)
|
| 801 |
|
| 802 |
+
# تنظیم چیدمان با st.radio
|
| 803 |
options = list(range(1, scale + 1))
|
| 804 |
+
current_value = st.session_state.get(key, 0)
|
| 805 |
|
| 806 |
+
# استفاده از st.radio
|
| 807 |
+
selected_value = st.radio(
|
| 808 |
+
"",
|
| 809 |
+
options=options,
|
| 810 |
+
index=current_value - 1 if current_value > 0 else None,
|
| 811 |
+
label_visibility="collapsed",
|
| 812 |
+
horizontal=True,
|
| 813 |
+
key=f"{key}_radio"
|
| 814 |
+
)
|
| 815 |
+
|
| 816 |
+
# بهروزرسانی st.session_state
|
| 817 |
+
if selected_value is not None and selected_value != current_value:
|
| 818 |
+
st.session_state[key] = selected_value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 819 |
|
| 820 |
# نمایش پاسخ انتخابشده
|
| 821 |
if st.session_state[key] != 0:
|
|
|
|
| 825 |
st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl;'>پاسخ شما: هنوز انتخاب نشده</p>",
|
| 826 |
unsafe_allow_html=True)
|
| 827 |
|
| 828 |
+
# خط جداکننده و استایل سفارشی
|
| 829 |
+
st.markdown(
|
| 830 |
+
"""
|
| 831 |
+
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 832 |
.likert-separator {
|
| 833 |
+
width: 80%;
|
| 834 |
+
height: 2px;
|
| 835 |
+
background: #6a0dad;
|
| 836 |
+
margin: 20px auto;
|
| 837 |
+
direction: rtl;
|
| 838 |
}
|
| 839 |
+
/* تنظیم استایل دکمههای رادیویی */
|
| 840 |
+
[data-testid="stRadio"] > div {
|
| 841 |
+
display: flex;
|
| 842 |
+
justify-content: space-between;
|
| 843 |
+
max-width: 475px;
|
| 844 |
+
margin: 0 auto;
|
| 845 |
+
padding: 0;
|
| 846 |
+
background: #6a0dad;
|
| 847 |
+
height: 2px;
|
| 848 |
+
align-items: center;
|
| 849 |
}
|
| 850 |
+
[data-testid="stRadio"] input[type="radio"] {
|
| 851 |
+
display: none;
|
| 852 |
+
}
|
| 853 |
+
[data-testid="stRadio"] label {
|
| 854 |
+
width: 18px !important;
|
| 855 |
+
height: 18px !important;
|
| 856 |
+
border-radius: 50% !important;
|
| 857 |
+
background: white !important;
|
| 858 |
+
border: 2px solid #6a0dad !important;
|
| 859 |
+
margin: 0 !important;
|
| 860 |
+
position: relative;
|
| 861 |
+
top: -9px;
|
| 862 |
+
cursor: pointer;
|
| 863 |
+
}
|
| 864 |
+
[data-testid="stRadio"] input[type="radio"]:checked + label {
|
| 865 |
+
background: #6a0dad !important;
|
| 866 |
+
}
|
| 867 |
+
@media (max-width: 768px) {
|
| 868 |
+
.likert-separator {
|
| 869 |
+
width: 90%;
|
| 870 |
+
}
|
| 871 |
+
[data-testid="stRadio"] > div {
|
| 872 |
+
width: 90%;
|
| 873 |
+
}
|
| 874 |
+
}
|
| 875 |
+
</style>
|
| 876 |
+
<div class="likert-separator"></div>
|
| 877 |
+
""",
|
| 878 |
+
unsafe_allow_html=True
|
| 879 |
+
)
|
| 880 |
|
| 881 |
return st.session_state.get(key)
|
| 882 |
|