Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -135,7 +135,38 @@ https://github.com/AaronCWacker/ThreeDragons
|
|
| 135 |

|
| 136 |
''')
|
| 137 |
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |

|
| 136 |
''')
|
| 137 |
|
| 138 |
+
# Function to handle repeated query parameters
|
| 139 |
+
def get_all_query_params(key):
|
| 140 |
+
return st.experimental_get_query_params().get(key, [])
|
| 141 |
|
| 142 |
+
# Function to clear all query parameters
|
| 143 |
+
def clear_query_params():
|
| 144 |
+
st.experimental_set_query_params() # Clear by setting to empty
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
st.title("Query Parameters Demo")
|
| 148 |
+
|
| 149 |
+
# Display current query parameters
|
| 150 |
+
st.write("Current Query Parameters:", st.experimental_get_query_params())
|
| 151 |
+
|
| 152 |
+
# Example: Using query parameters to navigate or trigger functionalities
|
| 153 |
+
if 'action' in st.experimental_get_query_params():
|
| 154 |
+
action = st.experimental_get_query_params()['action'][0] # Get the first (or only) 'action' parameter
|
| 155 |
+
if action == 'show_message':
|
| 156 |
+
st.success("Showing a message because 'action=show_message' was found in the URL.")
|
| 157 |
+
elif action == 'clear':
|
| 158 |
+
clear_query_params()
|
| 159 |
+
st.experimental_rerun()
|
| 160 |
+
|
| 161 |
+
# Handling repeated keys
|
| 162 |
+
if 'multi' in st.experimental_get_query_params():
|
| 163 |
+
multi_values = get_all_query_params('multi')
|
| 164 |
+
st.write("Values for 'multi':", multi_values)
|
| 165 |
+
|
| 166 |
+
# Manual entry for demonstration
|
| 167 |
+
st.write("Enter query parameters in the URL like this: ?action=show_message&multi=1&multi=2")
|
| 168 |
+
|
| 169 |
+
# Clear query parameters button
|
| 170 |
+
if st.button("Clear Query Parameters"):
|
| 171 |
+
clear_query_params()
|
| 172 |
+
st.experimental_rerun()
|