def checkbox(current_choice, session_state, **params): defaults = all_defaults_check(params['defaults']) if defaults == 1: defaults = True elif defaults == 0: defaults = False param_name = params['param_name'] final_name = element_description(current_choice, param_name) element_key = hash(param_name + current_choice + str(session_state)) return st.sidebar.checkbox(final_name, defaults, key=element_key)
def num_interval(current_choice, session_state, **params): defaults = all_defaults_check(params['defaults']) param_name = params['param_name'] final_name = element_description(current_choice, param_name) limits_list = limit_list_check(params['limits_list']) element_key = hash(final_name + current_choice + str(session_state)) return st.sidebar.slider( final_name, limits_list[0], limits_list[1], defaults, key=element_key, )
def several_nums(current_choice, session_state, **params): defaults = all_defaults_check(params['defaults_list']) limits_list = params['limits_list'] subparam_names = params['subparam_names'] return_list = [] for i, j in enumerate(subparam_names): new_par = { 'defaults': defaults[i], 'param_name': j, 'limits_list': limits_list[i], } return_list.append( num_interval(current_choice, session_state, **new_par), ) return return_list
def min_max(current_choice, session_state, **params): min_diff = 0 if 'min_diff' in params: min_diff = params.get('min_diff') limits_list = params['limits_list'] subparam_names = params['param_name'] param_name = ' & '.join(subparam_names) description_first = element_description(current_choice, subparam_names[0]) final_name = param_name + '( {0}; the same for {1})'.format( description_first, subparam_names[1], ) defaults = all_defaults_check(params['defaults_list']) new_params = { 'defaults': defaults, 'limits_list': limits_list, 'param_name': final_name, } result = list(num_interval( final_name, session_state, **new_params, ), ) min_val = result[0] max_val = result[1] if max_val - min_val < min_diff: diff = min_diff - result[1] + min_val if max_val + diff <= limits_list[1]: result[1] = result[1] + diff elif min_val - diff >= limits_list[0]: result[0] = result[0] - diff else: result = limits_list return result
def text_input(current_choice, session_state, **params): defaults = all_defaults_check(params['defaults']) param_name = params['param_name'] final_name = element_description(current_choice, param_name) return int(st.sidebar.text_input(final_name, defaults))