Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions hydralit/hydra_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Dict
import streamlit as st
from streamlit.logger import get_logger
import traceback
from datetime import datetime, timedelta, timezone
from hydralit.sessionstate import SessionState
from hydralit.loading_app import LoadingApp
Expand Down Expand Up @@ -30,7 +32,9 @@ def __init__(self,
use_banner_images=None,
banner_spacing=None,
clear_cross_app_sessions=True,
session_params=None):
session_params=None,
logger=None,
log_level='WARNING'):
"""
A class to create an Multi-app Streamlit application. This class will be the host application for multiple applications that are added after instancing.
The secret saurce to making the different apps work together comes from the use of a global session store that is shared with any HydraHeadApp that is added to the parent HydraApp.
Expand Down Expand Up @@ -82,7 +86,10 @@ def __init__(self,
A flag to indicate if the local session store values within individual apps should be cleared when moving to another app, if set to False, when loading sidebar controls, will be a difference between expected and selected.
session_params: Dict
A Dict of parameter name and default values that will be added to the global session store, these parameters will be available to all child applications and they can get/set values from the store during execution.

logger: Logger or True, None
A python logger that can provide traceback information on errors when running apps; if True, uses streamlit's logger
log_level: str, 'WARNING'
A string to set the logging level; only matters if you set the logger parameter
"""

self._apps = {}
Expand Down Expand Up @@ -120,8 +127,11 @@ def __init__(self,
self._guest_access = 1
self._hydralit_url_hash='hYDRALIT|-HaShing==seCr8t'
self._no_access_level = 0

self._user_session_params = session_params
self._logger = get_logger(__name__) if logger is True else logger

log_level_mapping = {'CRITICAL':50, 'ERROR':40, 'WARNING':30, 'INFO':20, 'DEBUG':10, 'NOTSET':0}
self._log_level = log_level_mapping[log_level.upper()]

try:
st.set_page_config(page_title=title,page_icon=favicon,layout=layout,initial_sidebar_state=sidebar_state,)
Expand Down Expand Up @@ -281,6 +291,9 @@ def _run_selected(self):
except Exception as e:
st.error('😭 Error triggered from app: **{}**'.format(self.session_state.selected_app))
st.error('Details: {}'.format(e))
if self._logger:
self._logger.log(level=self._log_level, msg=e)
self._logger.log(level=self._log_level, msg=traceback.format_exc())


def _clear_session_values(self):
Expand Down