Skip to content

Commit

Permalink
improve auto fetch urls for apps on CO
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhou committed Oct 21, 2023
1 parent baa24e7 commit db60782
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
27 changes: 26 additions & 1 deletion code/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import plotly.graph_objects as go
from scipy.stats import linregress
import statsmodels.api as sm
import json

from PIL import Image, ImageColor
import streamlit.components.v1 as components
import streamlit_nested_layout
from streamlit_plotly_events import plotly_events

from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector, add_caution
from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector
import extra_streamlit_components as stx

if_profile = False
Expand Down Expand Up @@ -61,6 +62,30 @@
if 'selected_points' not in st.session_state:
st.session_state['selected_points'] = []


def _get_urls():
cache_folder = 'aind-behavior-data/Han/ephys/report/st_cache/'
cache_session_level_fig_folder = 'aind-behavior-data/Han/ephys/report/all_sessions/'
cache_mouse_level_fig_folder = 'aind-behavior-data/Han/ephys/report/all_subjects/'

fs = s3fs.S3FileSystem(anon=False)

with fs.open('aind-behavior-data/Han/streamlit_CO_url.json', 'r') as f:
data = json.load(f)

return data['behavior'], data['ephys']

def add_caution():
behavior_url, ephys_url = _get_urls()
st.markdown('### ***:blue[❗️Caution: Due to bugs and resource limitations of the Streamlit public cloud, the app you are currently viewing may be unstable and buggy 🐞. '
f'It is recommended that you switch to [the one in Code Ocean]({behavior_url}) instead. '
'However, you will need to log in to Code Ocean first. Please contact David if you have any questions. '
f'See also [the ephys browser in Code Ocean]({ephys_url}) '
'(recommended) and [the one on the public cloud](https://foraging-ephys-browser.streamlit.app/)]***')

st.markdown('---')



@st.cache_data(ttl=24*3600)
def load_data(tables=['sessions']):
Expand Down
3 changes: 2 additions & 1 deletion code/pages/1_💡Population analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import numpy as np
from io import BytesIO

from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector, add_caution
from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector
from util.population import _draw_variable_trial_back, _draw_variable_trial_back_linear_reg
import seaborn as sns
from Home import add_caution


try:
Expand Down
3 changes: 2 additions & 1 deletion code/pages/2_🎬Video browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import plotly.graph_objs as go
from plotly.subplots import make_subplots

from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector, add_caution
from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector
from Home import add_caution
from streamlit_plotly_events import plotly_events
from util.population import _draw_variable_trial_back, _draw_variable_trial_back_linear_reg
import seaborn as sns
Expand Down
3 changes: 2 additions & 1 deletion code/pages/3_🌳Bonsai.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import streamlit_nested_layout
from streamlit_plotly_events import plotly_events

from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector, add_caution
from util.streamlit import filter_dataframe, aggrid_interactive_table_session, add_session_filter, data_selector
from Home import add_caution
import extra_streamlit_components as stx


Expand Down
10 changes: 0 additions & 10 deletions code/util/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@
"padding": "4px !important"},
}

def add_caution():
st.markdown('### ***:blue[❗️Caution: Due to bugs and resource limitations of the Streamlit public cloud, the app you are currently viewing may be unstable and buggy 🐞. '
'It is recommended that you switch to [the one in Code Ocean](https://codeocean.allenneuraldynamics.org/cw/cb1da92b-9a59-43ed-a609-65eb08119d36/proxy/8501/) instead. '
'However, you will need to log in to Code Ocean first. Please contact David if you have any questions. '
'See also [the ephys browser in Code Ocean](https://codeocean.allenneuraldynamics.org/cw/4617f5e4-c7ef-43f2-bcda-703d052e1b20/proxy/8501/) '
'(recommended) and [the one on the public cloud](https://foraging-ephys-browser.streamlit.app/)]***')

st.markdown('---')


def aggrid_interactive_table_session(df: pd.DataFrame):
"""Creates an st-aggrid interactive table based on a dataframe.
Expand Down

0 comments on commit db60782

Please sign in to comment.