variableselector module¶
- class VariableSelector(selected_inputs, selected_states, default_values=None)¶
Bases:
objectClass containing options for shared states between modules in the framework.
Notes
Each module should have its own instance of the VariableSelector in its __init__ function.
- Parameters:
selected_inputs (list[str])
selected_states (list[str])
default_values (dict[str, str | int | float] | None)
- get_all_callback_objects()¶
Retrieves a list of Dash Input and State objects for all selected variables.
- Return type:
list[Input|State]
- get_all_inputs()¶
Retrieves a list of Dash Input objects for selected inputs.
- Return type:
list[Input]
- get_all_states()¶
Retrieves a list of Dash State objects for selected states.
- Return type:
list[State]
- get_input(requested, search_target='title')¶
Retrieves a Input object for the selected variable.
- Return type:
Input- Parameters:
requested (str)
search_target (str)
- get_option(search_term, search_target='title')¶
Retrieves a VariableSelectorOption by variable name.
- Parameters:
search_term (str) – Word to search for, needs to be an exact match.
search_target (str) – Element of VariableSelectorOption to search.
- Return type:
- Returns:
VariableSelectorOption object matching description.
- Raises:
ValueError – If ‘search_target’ is not a searchable property.
Exception – If something goes wrong in a weird way.
- get_output_object(variable)¶
Creates a Dash Output object for a given variable.
Use this if you need to have a module output back to the shared VariableSelector in the main layout.
- Parameters:
variable (str) – The variable name.
- Returns:
The corresponding Dash Output object.
- Return type:
Output
- Raises:
ValueError – If the name (title) does not exist in any of the options available to the VariableSelector
- get_state(requested, search_target='title')¶
Retrieves a State object for the selected variable.
- Return type:
State- Parameters:
requested (str)
search_target (str)
- layout()¶
Generate a list of Dash Bootstrap cards based on selected variable keys.
- Return type:
list[Row]
- class VariableSelectorOption(variable_title, variable_id=None)¶
Bases:
objectRepresents an individual variable selection option.
- Parameters:
variable_title (str)
variable_id (str | None)
- set_variables(variable_list)¶
Sets the list of variables for the VariableSelector.
- Parameters:
variable_list (str | List[str]) – List of variable names to be added to the VariableSelector.
- Raises:
TypeError – If variable_list is not a string or a list of strings.
- Return type:
None
Examples
>>> set_variables("orgnr") >>> set_variables("kvartal") >>> set_variables(["foretak", "aar"])