GSMEthesis commited on
Commit
c3c733d
·
verified ·
1 Parent(s): b0de431

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -15
app.py CHANGED
@@ -739,27 +739,52 @@ h3 {
739
 
740
  # ========== توابع اصلی ==========
741
 
 
742
  def custom_likert_slider(question_data):
743
- """Radio buttons for Likert-style question"""
744
  question = question_data["question"]
745
  key = question_data["key"]
746
- labels = question_data.get("labels", ["کمترین", "بیشترین"])
 
747
 
748
- # Options for the Likert scale
749
- options = [str(i) for i in range(1, 6)] # Example for a 5-point Likert scale
750
-
751
- # Default value from session_state
752
- default_value = st.session_state.get(key, "3") # Default is the middle value
753
-
754
- # Radio button UI for Likert scale
755
- selected_value = st.radio(question, options, index=options.index(default_value), key=key)
756
 
757
- # Display the selected value
758
- st.write(f"انتخاب شده: {selected_value}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
759
 
760
- # Save the selected value to session_state
761
- st.session_state[key] = selected_value
762
- return selected_value
 
 
 
763
 
764
  def create_ride_map():
765
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
 
739
 
740
  # ========== توابع اصلی ==========
741
 
742
+
743
  def custom_likert_slider(question_data):
744
+ """Custom Likert-style question with circles and labels."""
745
  question = question_data["question"]
746
  key = question_data["key"]
747
+ scale = question_data["scale"]
748
+ labels = question_data.get("labels", ["کمترین", "بیشترین"]) # Default labels
749
 
750
+ # Default value (middle of the scale)
751
+ default_value = st.session_state.get(key, (scale + 1) // 2)
 
 
 
 
 
 
752
 
753
+ # HTML and CSS for custom Likert scale with radio buttons (styled as circles)
754
+ html = f"""
755
+ <div style="direction: ltr; font-family: 'B Nazanin'; margin-bottom: 30px;">
756
+ <label style="font-size: 16px; font-weight: bold; display: block; text-align: center;">{question}</label>
757
+ <div style="display: flex; justify-content: center; align-items: center; gap: 10px; margin: 10px 0;">
758
+ <span>{labels[0]}</span>
759
+ <div style="display: flex; gap: 10px;">
760
+ <input type="radio" id="radio_{key}_1" name="{key}" value="1" style="width: 30px; height: 30px;" {'checked' if default_value == 1 else ''} onclick="updateSlider(1, '{key}')">
761
+ <input type="radio" id="radio_{key}_2" name="{key}" value="2" style="width: 30px; height: 30px;" {'checked' if default_value == 2 else ''} onclick="updateSlider(2, '{key}')">
762
+ <input type="radio" id="radio_{key}_3" name="{key}" value="3" style="width: 30px; height: 30px;" {'checked' if default_value == 3 else ''} onclick="updateSlider(3, '{key}')">
763
+ <input type="radio" id="radio_{key}_4" name="{key}" value="4" style="width: 30px; height: 30px;" {'checked' if default_value == 4 else ''} onclick="updateSlider(4, '{key}')">
764
+ <input type="radio" id="radio_{key}_5" name="{key}" value="5" style="width: 30px; height: 30px;" {'checked' if default_value == 5 else ''} onclick="updateSlider(5, '{key}')">
765
+ </div>
766
+ <span>{labels[1]}</span>
767
+ </div>
768
+ </div>
769
+
770
+ <script>
771
+ function updateSlider(value, key) {{
772
+ // Send the value back to Streamlit
773
+ window.parent.postMessage({{
774
+ type: 'streamlit:setComponentValue',
775
+ key: key,
776
+ value: value
777
+ }}, '*');
778
+ }}
779
+ </script>
780
+ """
781
 
782
+ # Render the HTML and JavaScript in the Streamlit app
783
+ components.html(html, height=200)
784
+
785
+ # Return the value stored in session state, initially set to default value
786
+ slider_value = st.session_state.get(key, default_value)
787
+ return slider_value
788
 
789
  def create_ride_map():
790
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""