Spaces:
Sleeping
Sleeping
File size: 1,157 Bytes
cfcd3f8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import logging
try:
import streamlit as st
except ImportError:
logging.info("Streamlit not installed")
def check_streamlit():
"""
Function to check whether python code is run within streamlit
Returns
-------
use_streamlit : boolean
True if code is run within streamlit, else False
"""
try:
from streamlit.scriptrunner.script_run_context import get_script_run_ctx
if not get_script_run_ctx():
use_streamlit = False
else:
use_streamlit = True
except ModuleNotFoundError:
use_streamlit = False
return use_streamlit
def disable_other_checkboxes(*other_checkboxes_keys):
for checkbox_key in other_checkboxes_keys:
st.session_state[checkbox_key] = False
def checkbox_without_preselect(keylist):
dict_ = {}
for i,key_val in enumerate(keylist):
dict_[i] = st.checkbox(key_val,key = key_val,
on_change = disable_other_checkboxes,
args=tuple(list(filter(lambda x: x!= key_val, keylist))),)
for key,val in dict_.items():
if val == True:
return keylist[int(key)]
return None |