awacke1 commited on
Commit
06065a2
·
1 Parent(s): ca8fbc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -12
app.py CHANGED
@@ -1,20 +1,62 @@
1
  import streamlit as st
 
 
 
2
 
3
 
4
- def show_main_settings():
5
- st.write(f'Hi {st.session_state.query_params}')
 
 
 
 
 
 
 
6
 
 
 
 
7
 
8
- def run_dash():
9
- query_params = st.experimental_get_query_params()
10
- st.session_state.query_params = query_params
11
 
12
- if 'id' in query_params:
13
- show_main_settings()
14
- else:
15
- st.write('Malformed URL, missing id.')
16
- st.write(query_params)
17
 
 
18
 
19
- if __name__ == '__main__':
20
- run_dash()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ query_params = st.experimental_get_query_params()
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
+ # IMPORTANT: show only the data of the logged in customer
62
+ st.dataframe(data_df[data_df['customer'] == username])