-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multipage shared code and download changes (#7)
* add multipage loader and app_user file * fix pdf generation * change download button name * fix iframe styles * fix imports * fix dockerfile
- Loading branch information
Showing
24 changed files
with
137 additions
and
49 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
File renamed without changes.
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,13 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
from javascript.styles import add_styles | ||
import components.app_user as au | ||
import streamlit as st | ||
|
||
def load_multipage_app(): | ||
#Load user if logged in | ||
user = au.app_user() | ||
user.view_get_info() | ||
|
||
#load css | ||
add_styles() | ||
|
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,41 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
import streamlit as st | ||
from javascript.scripts import get_auth_user | ||
from util.session_variables import SessionVariables | ||
|
||
class app_user: | ||
|
||
sv = None | ||
|
||
def __init__(self, sv = None): | ||
if sv is not None: | ||
self.sv = sv | ||
else: | ||
self.sv = SessionVariables('home') | ||
self.login() | ||
|
||
def _get_info(self): | ||
return self.sv.username.value | ||
|
||
def _set_user(self, username): | ||
self.sv.username.value = username | ||
|
||
def view_get_info(self): | ||
if self.sv.username.value: | ||
st.sidebar.write(f"Logged in as {self.sv.username.value}") | ||
|
||
def _view_error_info(self, return_value): | ||
st.warning(f"Could not directly read username from azure active directory: {return_value}.") | ||
|
||
def login(self): | ||
if self.sv.mode.value != 'cloud': | ||
return | ||
return_value = get_auth_user() | ||
username = None | ||
if return_value == 0: | ||
pass # this is the result before the actual value is returned | ||
elif isinstance(return_value, list) and len(return_value) > 0: | ||
username = return_value[0]["user_id"] | ||
self._set_user(username) | ||
else: | ||
self._view_error_info(return_value) |
File renamed without changes.
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 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
from streamlit_javascript import st_javascript | ||
import streamlit as st | ||
|
||
def get_auth_user(): | ||
js_code = """await fetch("/.auth/me") | ||
.then(function(response) {return response.json();}) | ||
""" | ||
return st_javascript(js_code) |
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,25 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. All rights reserved. | ||
import streamlit as st | ||
|
||
style_sidebar = ''' | ||
[data-testid="stSidebarNavItems"] { | ||
max-height: 100vh | ||
} | ||
''' | ||
|
||
style_pdf = '''body { | ||
font-family: 'helvetica'; | ||
} | ||
''' | ||
|
||
style_iframes = ''' | ||
iframe { | ||
display: none; | ||
} | ||
''' | ||
|
||
def add_styles(): | ||
st.markdown(f'''<style> | ||
{style_sidebar} | ||
{style_iframes} | ||
</style>''', unsafe_allow_html=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
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
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
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
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
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