Hi.
I want to prevent the user to make certain combinations in st.multiselect()
.
I’m not quite sure if this is possible?
Example:
sel_vars = st.empty()
vars = sel_vars.multiselect("Pick one or multiple variables",
["N2O", "NO","N2","CH4"],
default=["N2O"])
# I want to disallow the user to match CH4 with any
# of the N-based selections since plotting them later in a
# graph does not make sense (the plot axis is kg N yr-1).
This is more of a python solution in general, by simply checking what elements are in the resulting list.
Otherwise the multiselect would have to have these filtering capabilities built in, which I don’t see happening because this could be very complicated to generalized for all cases.
import streamlit as st
def main():
sel_vars = st.empty()
vars = sel_vars.multiselect("Pick one or multiple variables",
["N2O", "NO", "N2", "CH4"],
default = ["N2O"])
st.write(vars)
if "CH4" in vars:
st.write("CH4 in vars")
if any([a in vars for a in ("N2O", "NO", "N2")]):
st.warning("Impossible combination")
return
if __name__ == "__main__":
main()
1 Like
Of course!
If did not have a main() function in this script and thus could not simply use return .
Thanks!