import streamlit as st import requests import json import web3 total_number_pages = 4 placeholder_buttons = None Q1_radio_options = ["radio option 1","radio option 2","radio option 3","Option 4?"] Q3_radio_options = ["Wowzers","This is super crazy","Not very crazy","midly crazy"] Q4_radio_options = ["Def not crazy","Crazy","Pizza","What am I doing?"] Q6_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"] # 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("", unsafe_allow_html=True) st.markdown("", 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["Q4"] = None st.session_state["Q5"] = None st.session_state["Q6"] = None st.session_state["disabled"] = False # Page 1; Video if st.session_state["current_page"] == 1: st.markdown("""
This is a test survey
""", unsafe_allow_html=True) st.radio(label = "This is the radio question", options = Q1_radio_options, index = None if st.session_state["Q1"] == None else st.session_state["Q1"], key = 'Q1_radio', on_change = radio_change, args = (Q1_radio_options, "Q1", "Q1_radio",)) st.markdown("""Rick rolled
""", unsafe_allow_html=True) st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSU_fgVbH_LfgbKK6qvziW5SgG7vxdoNMI-atQ3T7fYpX14W3u9ib3G1aMFB-9Se-INjq9RRPjpADux5kP09LaWcA") st.markdown("""Elephant
""", 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 or st.session_state["Q1"] == []: 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.text_area(label = "This is a text input question!", value= "" if st.session_state["Q2"] == None else st.session_state["Q2"], key = 'Q2_text', on_change = answer_change, args = ( "Q2", "Q2_text",)) st.markdown("""Yay a nice blank page
""", 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 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"] == 4: # Last Page st.markdown('Thank you for participating!
Click on the button below to submit your answers.