Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -772,32 +772,33 @@ def custom_likert_slider(question_data):
|
|
| 772 |
const value = parseInt(slider.value);
|
| 773 |
document.getElementById('output_' + key).innerText = value;
|
| 774 |
|
| 775 |
-
// ذخیره مقدار در یک متغیر مخفی برای دسترسی Streamlit
|
| 776 |
window.sliderValues = window.sliderValues || {{}};
|
| 777 |
window.sliderValues[key] = value;
|
| 778 |
|
| 779 |
-
// ارسال مقدار به Streamlit
|
| 780 |
try {{
|
| 781 |
window.parent.postMessage({{
|
| 782 |
type: 'streamlit:setComponentValue',
|
| 783 |
-
key: key,
|
| 784 |
value: value
|
| 785 |
}}, '*');
|
| 786 |
}} catch (e) {{
|
| 787 |
console.error('Error sending message to Streamlit:', e);
|
| 788 |
}}
|
| 789 |
|
| 790 |
-
// ذخیره مقدار در localStorage برای اطمینان
|
| 791 |
localStorage.setItem(key, value);
|
| 792 |
}}
|
| 793 |
-
|
| 794 |
-
// بازیابی مقدار اولیه از localStorage اگر وجود داشته باشد
|
| 795 |
window.addEventListener('load', () => {{
|
| 796 |
const key = '{key}';
|
| 797 |
const savedValue = localStorage.getItem(key);
|
| 798 |
if (savedValue) {{
|
| 799 |
document.getElementById(key).value = savedValue;
|
| 800 |
document.getElementById('output_' + key).innerText = savedValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
}}
|
| 802 |
});
|
| 803 |
</script>
|
|
@@ -810,22 +811,6 @@ def custom_likert_slider(question_data):
|
|
| 810 |
if key in st.session_state:
|
| 811 |
current_value = st.session_state[key]
|
| 812 |
else:
|
| 813 |
-
# تلاش برای خواندن از localStorage از طریق JavaScript
|
| 814 |
-
st.markdown(
|
| 815 |
-
f"""
|
| 816 |
-
<script>
|
| 817 |
-
const savedValue = localStorage.getItem('{key}');
|
| 818 |
-
if (savedValue) {{
|
| 819 |
-
window.parent.postMessage({{
|
| 820 |
-
type: 'streamlit:setComponentValue',
|
| 821 |
-
key: '{key}',
|
| 822 |
-
value: parseInt(savedValue)
|
| 823 |
-
}}, '*');
|
| 824 |
-
}}
|
| 825 |
-
</script>
|
| 826 |
-
""",
|
| 827 |
-
unsafe_allow_html=True
|
| 828 |
-
)
|
| 829 |
current_value = st.session_state.get(key, default_value)
|
| 830 |
|
| 831 |
# برای دیباگ: نمایش مقدار فعلی
|
|
|
|
| 772 |
const value = parseInt(slider.value);
|
| 773 |
document.getElementById('output_' + key).innerText = value;
|
| 774 |
|
|
|
|
| 775 |
window.sliderValues = window.sliderValues || {{}};
|
| 776 |
window.sliderValues[key] = value;
|
| 777 |
|
|
|
|
| 778 |
try {{
|
| 779 |
window.parent.postMessage({{
|
| 780 |
type: 'streamlit:setComponentValue',
|
| 781 |
+
key: "{key}",
|
| 782 |
value: value
|
| 783 |
}}, '*');
|
| 784 |
}} catch (e) {{
|
| 785 |
console.error('Error sending message to Streamlit:', e);
|
| 786 |
}}
|
| 787 |
|
|
|
|
| 788 |
localStorage.setItem(key, value);
|
| 789 |
}}
|
| 790 |
+
|
|
|
|
| 791 |
window.addEventListener('load', () => {{
|
| 792 |
const key = '{key}';
|
| 793 |
const savedValue = localStorage.getItem(key);
|
| 794 |
if (savedValue) {{
|
| 795 |
document.getElementById(key).value = savedValue;
|
| 796 |
document.getElementById('output_' + key).innerText = savedValue;
|
| 797 |
+
window.parent.postMessage({{
|
| 798 |
+
type: 'streamlit:setComponentValue',
|
| 799 |
+
key: "{key}",
|
| 800 |
+
value: parseInt(savedValue)
|
| 801 |
+
}}, '*');
|
| 802 |
}}
|
| 803 |
});
|
| 804 |
</script>
|
|
|
|
| 811 |
if key in st.session_state:
|
| 812 |
current_value = st.session_state[key]
|
| 813 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
current_value = st.session_state.get(key, default_value)
|
| 815 |
|
| 816 |
# برای دیباگ: نمایش مقدار فعلی
|