File size: 4,460 Bytes
20da062
693ede2
df914dc
a9f0da4
693ede2
a9f0da4
df914dc
693ede2
a9f0da4
693ede2
 
df914dc
 
 
a9f0da4
 
 
 
 
 
df914dc
 
 
693ede2
a9f0da4
 
 
df914dc
a9f0da4
693ede2
df914dc
 
693ede2
 
df914dc
 
a9f0da4
 
 
df914dc
693ede2
df914dc
 
693ede2
a9f0da4
df914dc
693ede2
a9f0da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df914dc
693ede2
df914dc
 
 
 
 
 
 
 
a9f0da4
df914dc
 
 
 
 
 
 
693ede2
a9f0da4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import streamlit as st
import requests
import json
# import web3

total_number_pages = 2
placeholder_buttons = None

Q3_radio_options = ["Fresh","Soph","Jr","Sr","N/A"]


# Function that records radio element changes
def radio_change(element, state, key):
   st.session_state[state] = element.index(st.session_state[key]) # Setting previously selected option

def multi_change(element, state, key):
   st.session_state[state] = []
   for selected_option in st.session_state[key]:
       st.session_state[state].append(selected_option)

# Function that disables the last button while data is uploaded to IPFS
def button_disable():
   st.session_state['disabled'] = True

def answer_change(state, key):
   st.session_state[state] = st.session_state[key]

st.set_page_config(page_title='IPFS-Based Survey',)
st.title('test survey')

st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)


if "current_page" not in st.session_state:
    st.session_state["current_page"] = 1
    st.session_state["Q1"] = None
    st.session_state["Q2"] = None
    st.session_state["Q3"] = None
    st.session_state["disabled"] = False

# Page 1; Video
if st.session_state["current_page"]  == 1:

    st.markdown("""<p class="big-font">this is a test</p>""", unsafe_allow_html=True)
    st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM")

    st.text_area(label     = "whats your favorite color", 
             value= "" if st.session_state["Q1"] == None else st.session_state["Q1"],
             key       = 'Q1_text', 
             on_change = answer_change,
             args      = ( "Q1", "Q1_text",))

    # The code below changes the font size of the above radio's label.
    st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)


    st.slider(label="how confident are you in your ability to skate",min_value=0,max_value=10, 
                           value= 5 if st.session_state["Q2"] == None else st.session_state["Q2"], 
                           key = "Q2_slider",
                           on_change = answer_change, 
                           args = ("Q2", "Q2_slider",))
    # The code below changes the font size of the above radio's label.
    st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)


    placeholder = st.empty()

    if st.button('Next', key='next_button_page_1'):
        all_answered = True
        if st.session_state["Q1"] == None:
            all_answered = False
        if st.session_state["Q2"] == None:
            all_answered = False
        if all_answered:
            st.session_state["current_page"] += 1
            st.rerun()
        else:
            with placeholder.container():
                st.warning("Please answer all the questions on this page.", icon="⚠️")

    st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")


elif st.session_state["current_page"] == 2:

    st.radio(label     = "what year are you in college", 
             options   = Q3_radio_options, 
             index     = None if st.session_state["Q3"] == None else st.session_state["Q3"], 
             key       = 'Q3_radio', 
             on_change = radio_change, 
             args      = (Q3_radio_options, "Q3", "Q3_radio",))

    # The code below changes the font size of the above radio's label.
    st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)


    placeholder = st.empty()

    col1, col2 = st.columns(2)
    with col1:
        if st.button('Back'):
            st.session_state["current_page"] -= 1
            st.rerun()
    with col2:
        if st.button('Next'):
            all_answered = True
            if st.session_state["Q3"] == None:
                all_answered = False
            if all_answered:
                st.session_state["current_page"] += 1
                st.rerun()
            else:
                with placeholder.container():
                    st.warning("Please answer all the questions on this page.", icon="⚠️")

    st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")