Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,14 +15,61 @@ def build_dataframe(rows_count=100):
|
|
15 |
'clicks': np.random.randint(low=0, high=1000, size=rows_count),
|
16 |
'customer': random.choices(['ShirtsInc', 'ShoesCom'], k=rows_count)
|
17 |
}
|
|
|
18 |
df = pd.DataFrame(data)
|
19 |
# add a date column and calculate the weekday of each row
|
20 |
-
df['date'] = pd.date_range(start='
|
|
|
21 |
return df
|
22 |
|
|
|
23 |
data_df = build_dataframe()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
st.title('Streamlit routing dashboard')
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
# callback to update query param on selectbox change
|
|
|
15 |
'clicks': np.random.randint(low=0, high=1000, size=rows_count),
|
16 |
'customer': random.choices(['ShirtsInc', 'ShoesCom'], k=rows_count)
|
17 |
}
|
18 |
+
|
19 |
df = pd.DataFrame(data)
|
20 |
# add a date column and calculate the weekday of each row
|
21 |
+
df['date'] = pd.date_range(start='1/1/2018', periods=rows_count)
|
22 |
+
|
23 |
return df
|
24 |
|
25 |
+
|
26 |
data_df = build_dataframe()
|
27 |
+
|
28 |
+
query_params = st.experimental_get_query_params()
|
29 |
+
# There is only one value for each parameter, retrieve the one at # # index 0
|
30 |
+
username = query_params.get('username', None)[0]
|
31 |
+
password = query_params.get('password', None)[0]
|
32 |
+
view = query_params.get('view', None)[0]
|
33 |
+
|
34 |
+
# Super basic (and not recommended) way to store the credentials
|
35 |
+
# Just for illustrative purposes!
|
36 |
+
credentials = {
|
37 |
+
'ShoesCom': 'shoespassword',
|
38 |
+
'ShirtsInc': 'shirtspassword'
|
39 |
+
}
|
40 |
+
|
41 |
+
logged_in = False
|
42 |
+
|
43 |
+
# Check that the username exists in the "database" and that the provided password matches
|
44 |
+
if username in credentials and credentials[username] == password:
|
45 |
+
logged_in = True
|
46 |
+
|
47 |
+
if not logged_in:
|
48 |
+
# If credentials are invalid show a message and stop rendering the webapp
|
49 |
+
st.warning('Invalid credentials')
|
50 |
+
st.stop()
|
51 |
+
|
52 |
+
available_views = ['report']
|
53 |
+
if view not in available_views:
|
54 |
+
# I don't know which view do you want. Beat it.
|
55 |
+
st.warning('404 Error')
|
56 |
+
st.stop()
|
57 |
+
# The username exists and the password matches!
|
58 |
+
# Also, the required view exists
|
59 |
+
# Show the webapp
|
60 |
+
|
61 |
st.title('Streamlit routing dashboard')
|
62 |
+
|
63 |
+
# IMPORTANT: show only the data of the logged in customer
|
64 |
+
st.dataframe(data_df[data_df['customer'] == username])
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
|
74 |
|
75 |
# callback to update query param on selectbox change
|