Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,25 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import random
|
4 |
-
import numpy as np
|
5 |
-
|
6 |
-
|
7 |
-
def build_dataframe(rows_count=100):
|
8 |
-
"""
|
9 |
-
Creates columns with random data.
|
10 |
-
"""
|
11 |
-
data = {
|
12 |
-
'impressions': np.random.randint(low=111, high=10000, size=rows_count),
|
13 |
-
'clicks': np.random.randint(low=0, high=1000, size=rows_count),
|
14 |
-
'customer': random.choices(['ShirtsInc', 'ShoesCom'], k=rows_count)
|
15 |
-
}
|
16 |
-
|
17 |
-
df = pd.DataFrame(data)
|
18 |
-
# add a date column and calculate the weekday of each row
|
19 |
-
df['date'] = pd.date_range(start='1/1/2018', periods=rows_count)
|
20 |
-
|
21 |
-
return df
|
22 |
-
|
23 |
-
|
24 |
-
data_df = build_dataframe()
|
25 |
|
26 |
-
|
27 |
-
# There is only one value for each parameter, retrieve the one at # # index 0
|
28 |
-
username = query_params.get('username', None)[0]
|
29 |
-
password = query_params.get('password', None)[0]
|
30 |
-
view = query_params.get('view', None)[0]
|
31 |
-
|
32 |
-
# Super basic (and not recommended) way to store the credentials
|
33 |
-
# Just for illustrative purposes!
|
34 |
-
credentials = {
|
35 |
-
'ShoesCom': 'shoespassword',
|
36 |
-
'ShirtsInc': 'shirtspassword'
|
37 |
-
}
|
38 |
-
|
39 |
-
logged_in = False
|
40 |
-
|
41 |
-
# Check that the username exists in the "database" and that the provided password matches
|
42 |
-
if username in credentials and credentials[username] == password:
|
43 |
-
logged_in = True
|
44 |
-
|
45 |
-
if not logged_in:
|
46 |
-
# If credentials are invalid show a message and stop rendering the webapp
|
47 |
-
st.warning('Invalid credentials')
|
48 |
-
st.stop()
|
49 |
-
|
50 |
-
available_views = ['report']
|
51 |
-
if view not in available_views:
|
52 |
-
# I don't know which view do you want. Beat it.
|
53 |
-
st.warning('404 Error')
|
54 |
-
st.stop()
|
55 |
-
# The username exists and the password matches!
|
56 |
-
# Also, the required view exists
|
57 |
-
# Show the webapp
|
58 |
-
|
59 |
-
st.title('Streamlit routing dashboard')
|
60 |
|
61 |
-
|
62 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
def query_params():
|
5 |
+
st.write("""
|
6 |
+
# Introducing Query Params
|
7 |
+
We have added to our experimental namespace the ability to get and set
|
8 |
+
query parameters. With these query params, you can bookmark or share your app
|
9 |
+
in various states. Thanks [@zhaoooyue](https://github.com/zhaoooyue) for the
|
10 |
+
contribution!
|
11 |
+
""")
|
12 |
+
with st.echo("below"):
|
13 |
+
radio_list = ['Eat', 'Sleep', 'Both']
|
14 |
+
query_params = st.experimental_get_query_params()
|
15 |
+
|
16 |
+
# Query parameters are returned as a list to support multiselect.
|
17 |
+
# Get the first item in the list if the query parameter exists.
|
18 |
+
default = int(query_params["activity"][0]) if "activity" in query_params else 0
|
19 |
+
activity = st.radio(
|
20 |
+
"What are you doing at home during quarantine?",
|
21 |
+
radio_list,
|
22 |
+
index = default
|
23 |
+
)
|
24 |
+
if activity:
|
25 |
+
st.experimental_set_query_params(activity=radio_list.index(activity))
|