Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,7 +739,7 @@ h3 {
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
-
"""لیکرت اسکیل با دکمههای کاملاً HTML و
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
@@ -748,8 +748,6 @@ def enhanced_likert_scale(question_data):
|
|
| 748 |
# مقداردهی اولیه
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
-
if f"{key}_temp" not in st.session_state:
|
| 752 |
-
st.session_state[f"{key}_temp"] = st.session_state[key] or None
|
| 753 |
|
| 754 |
# استایلدهی و ساختار HTML
|
| 755 |
html_content = f"""
|
|
@@ -813,23 +811,6 @@ def enhanced_likert_scale(question_data):
|
|
| 813 |
margin-top: 10px !important;
|
| 814 |
font-size: 16px !important;
|
| 815 |
}}
|
| 816 |
-
/* دکمه تأیید */
|
| 817 |
-
.confirm-btn {{
|
| 818 |
-
background-color: #6a0dad !important;
|
| 819 |
-
color: white !important;
|
| 820 |
-
border: none !important;
|
| 821 |
-
border-radius: 8px !important;
|
| 822 |
-
padding: 10px 20px !important;
|
| 823 |
-
font-weight: bold !important;
|
| 824 |
-
cursor: pointer !important;
|
| 825 |
-
margin-top: 15px !important;
|
| 826 |
-
transition: all 0.3s ease !important;
|
| 827 |
-
}}
|
| 828 |
-
.confirm-btn:hover {{
|
| 829 |
-
background-color: #5a0a96 !important;
|
| 830 |
-
transform: translateY(-1px) !important;
|
| 831 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
|
| 832 |
-
}}
|
| 833 |
</style>
|
| 834 |
<div class="likert-container">
|
| 835 |
<div class="likert-question">{question}</div>
|
|
@@ -843,7 +824,7 @@ def enhanced_likert_scale(question_data):
|
|
| 843 |
# افزودن دکمههای HTML
|
| 844 |
for i in range(scale):
|
| 845 |
value = scale - i # 7 تا 1
|
| 846 |
-
is_selected = st.session_state[
|
| 847 |
html_content += f"""
|
| 848 |
<button class="likert-btn {'selected' if is_selected else ''}"
|
| 849 |
onclick="selectLikert('{key}', {value})">
|
|
@@ -854,41 +835,52 @@ def enhanced_likert_scale(question_data):
|
|
| 854 |
html_content += f"""
|
| 855 |
</div>
|
| 856 |
<div class="likert-response" id="likert-response-{key}">
|
| 857 |
-
پاسخ شما: {st.session_state[
|
| 858 |
</div>
|
| 859 |
-
<button class="confirm-btn" onclick="confirmSelection('{key}')">
|
| 860 |
-
تأیید
|
| 861 |
-
</button>
|
| 862 |
</div>
|
| 863 |
<script>
|
| 864 |
function selectLikert(key, value) {{
|
| 865 |
-
// بهروزرسانی متغیر موقت
|
| 866 |
-
window.sessionStorage.setItem('{key}_temp', value);
|
| 867 |
// بهروزرسانی استایل دکمهها
|
| 868 |
const buttons = document.querySelectorAll('#likert-buttons-{key} .likert-btn');
|
| 869 |
buttons.forEach(btn => btn.classList.remove('selected'));
|
| 870 |
event.currentTarget.classList.add('selected');
|
| 871 |
// بهروزرسانی متن پاسخ
|
| 872 |
document.getElementById('likert-response-{key}').innerText = 'پاسخ شما: ' + value;
|
| 873 |
-
}}
|
| 874 |
-
function confirmSelection(key) {{
|
| 875 |
// فعال کردن دکمه مخفی Streamlit
|
| 876 |
-
document.getElementById('
|
| 877 |
}}
|
| 878 |
</script>
|
| 879 |
"""
|
| 880 |
|
| 881 |
# رندر HTML
|
| 882 |
-
components.html(html_content, height=
|
| 883 |
|
| 884 |
-
# دکمه مخفی Streamlit برای
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 889 |
st.rerun()
|
| 890 |
|
| 891 |
return st.session_state.get(key)
|
|
|
|
| 892 |
|
| 893 |
def create_ride_map():
|
| 894 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
|
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
+
"""لیکرت اسکیل با دکمههای کاملاً HTML بدون دکمه تأیید"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
|
|
| 748 |
# مقداردهی اولیه
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
|
|
|
|
|
|
| 751 |
|
| 752 |
# استایلدهی و ساختار HTML
|
| 753 |
html_content = f"""
|
|
|
|
| 811 |
margin-top: 10px !important;
|
| 812 |
font-size: 16px !important;
|
| 813 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
</style>
|
| 815 |
<div class="likert-container">
|
| 816 |
<div class="likert-question">{question}</div>
|
|
|
|
| 824 |
# افزودن دکمههای HTML
|
| 825 |
for i in range(scale):
|
| 826 |
value = scale - i # 7 تا 1
|
| 827 |
+
is_selected = st.session_state[key] == value
|
| 828 |
html_content += f"""
|
| 829 |
<button class="likert-btn {'selected' if is_selected else ''}"
|
| 830 |
onclick="selectLikert('{key}', {value})">
|
|
|
|
| 835 |
html_content += f"""
|
| 836 |
</div>
|
| 837 |
<div class="likert-response" id="likert-response-{key}">
|
| 838 |
+
پاسخ شما: {st.session_state[key] or "هیچکدام"}
|
| 839 |
</div>
|
|
|
|
|
|
|
|
|
|
| 840 |
</div>
|
| 841 |
<script>
|
| 842 |
function selectLikert(key, value) {{
|
|
|
|
|
|
|
| 843 |
// بهروزرسانی استایل دکمهها
|
| 844 |
const buttons = document.querySelectorAll('#likert-buttons-{key} .likert-btn');
|
| 845 |
buttons.forEach(btn => btn.classList.remove('selected'));
|
| 846 |
event.currentTarget.classList.add('selected');
|
| 847 |
// بهروزرسانی متن پاسخ
|
| 848 |
document.getElementById('likert-response-{key}').innerText = 'پاسخ شما: ' + value;
|
|
|
|
|
|
|
| 849 |
// فعال کردن دکمه مخفی Streamlit
|
| 850 |
+
document.getElementById('hidden-btn-{key}-{value}').click();
|
| 851 |
}}
|
| 852 |
</script>
|
| 853 |
"""
|
| 854 |
|
| 855 |
# رندر HTML
|
| 856 |
+
components.html(html_content, height=200)
|
| 857 |
|
| 858 |
+
# ایجاد دکمههای مخفی Streamlit برای مدیریت کلیکها
|
| 859 |
+
for i in range(scale):
|
| 860 |
+
value = scale - i
|
| 861 |
+
# دکمههای مخفی با CSS غیرقابلمشاهده میشوند
|
| 862 |
+
st.markdown(
|
| 863 |
+
f"""
|
| 864 |
+
<style>
|
| 865 |
+
#hidden-btn-{key}-{value} {{
|
| 866 |
+
display: none !important;
|
| 867 |
+
}}
|
| 868 |
+
</style>
|
| 869 |
+
""",
|
| 870 |
+
unsafe_allow_html=True
|
| 871 |
+
)
|
| 872 |
+
if st.button(
|
| 873 |
+
"hidden",
|
| 874 |
+
key=f"hidden-btn-{key}-{value}",
|
| 875 |
+
help=str(value),
|
| 876 |
+
type="secondary",
|
| 877 |
+
use_container_width=True
|
| 878 |
+
):
|
| 879 |
+
st.session_state[key] = value
|
| 880 |
st.rerun()
|
| 881 |
|
| 882 |
return st.session_state.get(key)
|
| 883 |
+
|
| 884 |
|
| 885 |
def create_ride_map():
|
| 886 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|