Skip to content

utils

hide_streamlit_content()

Hide the footer message and deploy button in Streamlit.

Source code in src/nhssynth/modules/dashboard/utils.py
def hide_streamlit_content() -> None:
    """
    Hide the footer message and deploy button in Streamlit.
    """
    hide_streamlit_style = """
    <style>
    footer {visibility: hidden;}
    .stDeployButton {visibility: hidden;}
    </style>
    """
    st.markdown(hide_streamlit_style, unsafe_allow_html=True)

id_selector(df)

Select an ID from the dataframe to then operate on.

Parameters:

Name Type Description Default
df DataFrame

The dataframe to select an ID from.

required

Returns:

Type Description
Series

The dataset subset to only the row corresponding to the ID.

Source code in src/nhssynth/modules/dashboard/utils.py
def id_selector(df: pd.DataFrame) -> pd.Series:
    """
    Select an ID from the dataframe to then operate on.

    Args:
        df: The dataframe to select an ID from.

    Returns:
        The dataset subset to only the row corresponding to the ID.
    """
    architecture = st.sidebar.selectbox(
        "Select architecture to display", df.index.get_level_values("architecture").unique()
    )
    # Different architectures may have different numbers of repeats and configs
    repeats = df.loc[architecture].index.get_level_values("repeat").astype(int).unique()
    configs = df.loc[architecture].index.get_level_values("config").astype(int).unique()
    if len(repeats) > 1:
        repeat = st.sidebar.selectbox("Select repeat to display", repeats)
    else:
        repeat = repeats[0]
    if len(configs) > 1:
        config = st.sidebar.selectbox("Select configuration to display", configs)
    else:
        config = configs[0]
    return df.loc[(architecture, repeat, config)]

subset_selector(df)

Select a subset of the dataframe to then operate on.

Parameters:

Name Type Description Default
df DataFrame

The dataframe to select a subset of.

required

Returns:

Type Description
DataFrame

The subset of the dataframe.

Source code in src/nhssynth/modules/dashboard/utils.py
def subset_selector(df: pd.DataFrame) -> pd.DataFrame:
    """
    Select a subset of the dataframe to then operate on.

    Args:
        df: The dataframe to select a subset of.

    Returns:
        The subset of the dataframe.
    """
    architectures = df.index.get_level_values("architecture").unique().tolist()
    repeats = df.index.get_level_values("repeat").astype(int).unique().tolist()
    configs = df.index.get_level_values("config").astype(int).unique().tolist()
    selected_architectures = st.sidebar.multiselect(
        "Select architectures to display", architectures, default=architectures
    )
    selected_repeats = st.sidebar.multiselect("Select repeats to display", repeats, default=repeats[0])
    selected_configs = st.sidebar.multiselect("Select configurations to display", configs, default=configs)
    return df.loc[(selected_architectures, selected_repeats, selected_configs)]