-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce single page apps.
- Loading branch information
Showing
32 changed files
with
390 additions
and
73 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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
cd app || exit | ||
cd vro_streamlit || exit | ||
|
||
python -m streamlit run main.py |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from streamlit.testing.v1 import AppTest | ||
|
||
|
||
def test_main() -> None: | ||
app = AppTest.from_file('src/app/main.py') | ||
app = AppTest.from_file('src/vro_streamlit/main.py') | ||
app.run() | ||
assert not app.exception | ||
assert not app.exception |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from streamlit.testing.v1 import AppTest | ||
|
||
|
||
def test_main() -> None: | ||
app = AppTest.from_file('src/app/main.py') | ||
app = AppTest.from_file('src/vro_streamlit/main.py') | ||
app.run() | ||
assert not app.exception | ||
assert not app.exception |
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Empty file.
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,9 @@ | ||
from vro_streamlit.auth.user import User | ||
|
||
|
||
def log_in() -> User: | ||
return User('test') | ||
|
||
|
||
def log_out() -> bool: | ||
return True |
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 @@ | ||
class User: | ||
def __init__(self, username: str): | ||
self.username: str = username |
File renamed without changes.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions
24
vro-streamlit/src/vro_streamlit/directory/bie_events/claim_events.py
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,24 @@ | ||
# mypy: ignore-errors | ||
# Ignore until this class is implemented | ||
|
||
import streamlit as st | ||
|
||
from vro_streamlit.service.database import EVENTS_REPO | ||
|
||
|
||
def show(): # pragma: no cover | ||
st.header('BIE Claim Events') | ||
st.markdown( | ||
'The table below contains BIE Claim Events. For more information and descriptions of the individual fields. Please refer to the ' | ||
'[BIE Claim Events](https://confluence.devops.va.gov/display/VAExternal/Subdomain%3A+Claim+Events) domain page for BIE Events.' | ||
) | ||
st.markdown('*The data in this table is for demonstration purposes only and does not reflect real data.*') | ||
|
||
st.dataframe( | ||
EVENTS_REPO.get_claim_events(), | ||
hide_index=True, | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
show() |
24 changes: 24 additions & 0 deletions
24
vro-streamlit/src/vro_streamlit/directory/bie_events/contention_events.py
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,24 @@ | ||
# mypy: ignore-errors | ||
# Ignore until this class is implemented | ||
|
||
import streamlit as st | ||
|
||
from vro_streamlit.service.database import EVENTS_REPO | ||
|
||
|
||
def show(): # pragma: no cover | ||
st.header('BIE Contention Events') | ||
st.markdown( | ||
'The table below contains BIE Contention Events. For more information and descriptions of the individual fields. Please refer to the ' | ||
'[BIE Contention Events](https://github.com/department-of-veterans-affairs/abd-vro/wiki/BIE-Contention-Events-User-Guide) page in the VRO Wiki.' | ||
) | ||
st.markdown('*The data in this table is for demonstration purposes only and does not reflect real data.*') | ||
|
||
st.dataframe( | ||
EVENTS_REPO.get_contention_events(), | ||
hide_index=True, | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
show() |
Empty file.
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
12 changes: 2 additions & 10 deletions
12
vro-streamlit/src/app/pages/1_Text.py → .../vro_streamlit/directory/examples/text.py
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
13 changes: 3 additions & 10 deletions
13
...treamlit/src/app/pages/3_Water_Quality.py → ...amlit/directory/examples/water_quality.py
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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
# mypy: ignore-errors | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
|
||
# sidebar config | ||
st.sidebar.image('static/streamlit-logo.png') | ||
st.sidebar.button('Rerun') | ||
|
||
if 'color' not in st.session_state: | ||
st.session_state.color = '#FF0000' | ||
|
||
st.sidebar.write('Choose a datapoint color') | ||
st.session_state.color = st.sidebar.color_picker('Color', st.session_state.color) | ||
|
||
st.title('Water Quality (pH)') | ||
st.markdown('From [fws.gov](https://ecos.fws.gov/ServCat/DownloadFile/173741?Reference=117348)') | ||
df = pd.DataFrame(pd.read_csv('https://ecos.fws.gov/ServCat/DownloadFile/173741?Reference=117348'), columns=['Read_Date', 'pH (standard units)']) | ||
|
||
st.dataframe(df, use_container_width=True) | ||
|
||
st.line_chart(df, x='Read_Date', color=st.session_state.color) | ||
st.line_chart(df, x='Read_Date') |
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,35 @@ | ||
from importlib.resources import files | ||
|
||
import streamlit as st | ||
|
||
import vro_streamlit.auth.auth_service as auth | ||
|
||
LOGIN_BUTTON = 'home_login_button' | ||
LOGO = files('vro_streamlit').joinpath('static/streamlit-logo.png').read_bytes() | ||
|
||
|
||
def update_login_status() -> None: | ||
if not st.session_state.user: | ||
st.session_state.user = auth.log_in() | ||
else: | ||
if auth.log_out(): | ||
st.session_state.user = None | ||
|
||
|
||
def show() -> None: | ||
col1, col2 = st.columns([0.04, 0.96]) | ||
col1.image(LOGO, width=100) | ||
col2.header('Home') | ||
st.subheader('Welcome to the home page!') | ||
|
||
user = st.session_state.get('user') | ||
if user: | ||
st.write(f'Hello, {user.username}!') | ||
st.button('Log Out', key=LOGIN_BUTTON, on_click=update_login_status) | ||
else: | ||
st.write('Please Log In') | ||
st.button('Log In', key=LOGIN_BUTTON, on_click=update_login_status) | ||
|
||
|
||
if __name__ == '__main__': | ||
show() |
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,65 @@ | ||
import streamlit as st | ||
|
||
import vro_streamlit.auth.auth_service as auth | ||
import vro_streamlit.config as config | ||
import vro_streamlit.directory.home as home | ||
from vro_streamlit.directory.bie_events import claim_events, contention_events | ||
|
||
LOGIN_BUTTON = 'sidebar_login_button' | ||
LOGOUT_BUTTON = 'sidebar_logout_button' | ||
|
||
st.set_page_config(page_title='VRO Streamlit', layout='wide') | ||
|
||
|
||
def init_session_state() -> None: | ||
st.session_state.setdefault('database_connected', True) | ||
st.session_state.setdefault('user', None) | ||
|
||
|
||
def update_login_status() -> None: | ||
if not st.session_state.user: | ||
st.session_state.user = auth.log_in() | ||
else: | ||
if auth.log_out(): | ||
st.session_state.user = None | ||
|
||
|
||
def create_navigation() -> None: | ||
home_page = st.Page(home.show, title='Home', default=True) | ||
# BIE events | ||
bie_events = [ | ||
st.Page(claim_events.show, title='Claim Events', url_path='/claim_events'), | ||
st.Page(contention_events.show, title='Contention Events', url_path='/contention_events'), | ||
] | ||
# examples | ||
examples = [ | ||
st.Page('directory/examples/text.py', title='Text'), | ||
st.Page('directory/examples/dataframes.py', title='Dataframes'), | ||
st.Page('directory/examples/water_quality.py', title='Water Quality'), | ||
] | ||
nav = st.navigation({'Main': [home_page], 'BIE Events': bie_events, 'Examples': examples}) | ||
nav.run() | ||
|
||
|
||
def create_sidebar() -> None: | ||
with st.sidebar: | ||
with st.container(border=True): | ||
col1, col2 = st.columns(2) | ||
with col1: | ||
st.markdown('Environment', help='Current operating environment') | ||
st.markdown('Database', help='Database connection status') | ||
st.markdown('Authorized', help='User authorization status') | ||
with col2: | ||
st.markdown(f'`{config.ENV}`') | ||
st.markdown(':large_green_circle:' if st.session_state.database_connected else ':red_circle:', unsafe_allow_html=True) | ||
st.markdown(':large_green_circle:' if st.session_state.user else ':red_circle:', unsafe_allow_html=True) | ||
|
||
button_text = 'Log Out' if st.session_state.user else 'Log In' | ||
button_key = LOGOUT_BUTTON if st.session_state.user else LOGIN_BUTTON | ||
st.button(button_text, use_container_width=True, on_click=update_login_status, key=button_key) | ||
|
||
|
||
if __name__ == '__main__': | ||
init_session_state() | ||
create_sidebar() | ||
create_navigation() |
Empty file.
Oops, something went wrong.