-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dashbaord functions, configs, fake secrets.
- Loading branch information
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Git ignore everything in this directory | ||
* | ||
# Except these files | ||
!.gitignore | ||
!config.toml | ||
|
||
# In production, this file should not be pushed to Github. | ||
!secrets.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[browser] | ||
gatherUsageStats = false | ||
|
||
[client] | ||
toolbarMode = "viewer" | ||
|
||
# default theme | ||
[theme] | ||
base="dark" | ||
#primaryColor="#F63366" | ||
|
||
backgroundColor="#000000" # Black | ||
|
||
#secondaryBackgroundColor="#F0F2F6" | ||
#textColor="#262730" | ||
|
||
## Primary accent for interactive elements | ||
#primaryColor = '#7792E3' | ||
|
||
## Background color for the main content area | ||
#backgroundColor = '#152630' | ||
|
||
## Background color for sidebar and most interactive widgets | ||
#secondaryBackgroundColor = '#bfbfbf' | ||
|
||
## Color used for almost all text | ||
#textColor = '#0693e3' | ||
|
||
## Font family for all text in the app, except code blocks | ||
# Accepted values (serif | sans serif | monospace) | ||
font = "sans serif" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Add in gitignore in production | ||
username = "r4m_worth" | ||
password = "$millions" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Create a version of a "Challenge" Dashboard for the public demo. | ||
""" | ||
|
||
import sys | ||
|
||
import streamlit as st | ||
|
||
from streamlit_auth import check_password | ||
|
||
# Import modules from src when run from a folder next to src. | ||
sys.path.append("../src") | ||
|
||
from utils.all_plots_from_df import create_all_charts_from_feather_file | ||
from utils.dashboard_plot_configs import ( | ||
hide_streamlit_instructions, | ||
hide_streamlit_style, | ||
) | ||
|
||
if __name__ == "__main__": | ||
# Request user authentication | ||
if "authenticated" not in st.session_state: | ||
st.markdown(hide_streamlit_style, unsafe_allow_html=True) | ||
st.session_state["authenticated"] = False | ||
hide_streamlit_instructions() | ||
|
||
# Check password | ||
check_password() | ||
# Initialize session state | ||
if st.session_state["authenticated"]: | ||
st.markdown(hide_streamlit_style, unsafe_allow_html=True) | ||
st.markdown( | ||
"<h5 style='text-align: center; color: #0693e3;'>Run4More <strong>analytics</strong> Demo</h5>", | ||
unsafe_allow_html=True, | ||
) | ||
|
||
# Dashboard from feather file | ||
create_all_charts_from_feather_file("./data/acts_by_date_trend.feather") | ||
|
||
else: | ||
st.info( | ||
"Please login by clicking on the Login button. Username: `r4m_worth`, Pwd: `$millions`." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import hashlib | ||
|
||
import streamlit as st | ||
|
||
from utils.dashboard_plot_configs import hide_streamlit_instructions | ||
|
||
|
||
def hash_password(password: str) -> str: | ||
""" | ||
Hash the password. | ||
Args: password: string. | ||
Return: string. | ||
""" | ||
return hashlib.sha256(str.encode(password)).hexdigest() | ||
|
||
|
||
def check_password() -> None: | ||
""" | ||
Check the password for the public dashboard. | ||
return: None | ||
""" | ||
|
||
# Define your username and password hash | ||
hide_streamlit_instructions() | ||
correct_username = st.secrets["username"] | ||
correct_password_hash = hash_password(st.secrets["password"]) | ||
|
||
# Create placeholders for the login inputs and button | ||
username_placeholder = st.empty() | ||
password_placeholder = st.empty() | ||
button_placeholder = st.empty() | ||
custom_message_placeholder = st.empty() | ||
|
||
# Only display login inputs and button if the user is not authenticated | ||
if not st.session_state.get("authenticated", False): | ||
hide_streamlit_instructions() | ||
# Input fields | ||
username = username_placeholder.text_input("Username", key="username_input") | ||
password = password_placeholder.text_input( | ||
"Password", | ||
key="password_input", | ||
type="password", | ||
) | ||
|
||
# Check the password | ||
if button_placeholder.button("Login"): | ||
if ( | ||
username == correct_username | ||
and hash_password(password) == correct_password_hash | ||
): | ||
st.session_state["authenticated"] = True | ||
# Clear the placeholders after a successful login | ||
username_placeholder.empty() | ||
password_placeholder.empty() | ||
button_placeholder.empty() | ||
custom_message_placeholder.empty() | ||
else: | ||
st.error("Incorrect username or password.") | ||
return None |