Spaces:
Runtime error
Runtime error
File size: 1,829 Bytes
ecf3beb 06065a2 ecf3beb 06065a2 ca8fbc6 06065a2 ca8fbc6 06065a2 ca8fbc6 ecf3beb 06065a2 ecf3beb 06065a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import streamlit as st
import pandas as pd
import random
import numpy as np
def build_dataframe(rows_count=100):
"""
Creates columns with random data.
"""
data = {
'impressions': np.random.randint(low=111, high=10000, size=rows_count),
'clicks': np.random.randint(low=0, high=1000, size=rows_count),
'customer': random.choices(['ShirtsInc', 'ShoesCom'], k=rows_count)
}
df = pd.DataFrame(data)
# add a date column and calculate the weekday of each row
df['date'] = pd.date_range(start='1/1/2018', periods=rows_count)
return df
data_df = build_dataframe()
query_params = st.experimental_get_query_params()
# There is only one value for each parameter, retrieve the one at # # index 0
username = query_params.get('username', None)[0]
password = query_params.get('password', None)[0]
view = query_params.get('view', None)[0]
# Super basic (and not recommended) way to store the credentials
# Just for illustrative purposes!
credentials = {
'ShoesCom': 'shoespassword',
'ShirtsInc': 'shirtspassword'
}
logged_in = False
# Check that the username exists in the "database" and that the provided password matches
if username in credentials and credentials[username] == password:
logged_in = True
if not logged_in:
# If credentials are invalid show a message and stop rendering the webapp
st.warning('Invalid credentials')
st.stop()
available_views = ['report']
if view not in available_views:
# I don't know which view do you want. Beat it.
st.warning('404 Error')
st.stop()
# The username exists and the password matches!
# Also, the required view exists
# Show the webapp
st.title('Streamlit routing dashboard')
# IMPORTANT: show only the data of the logged in customer
st.dataframe(data_df[data_df['customer'] == username]) |