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])