Skip to content

Commit

Permalink
pretty replicate buttons with radio interface
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Nov 7, 2023
1 parent 3d7b416 commit 33fe11a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions gooey_ui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,45 @@ def table(df: "pd.DataFrame"):
).mount()


def horizontal_radio(
label: str,
options: typing.Sequence[T],
format_func: typing.Callable[[T], typing.Any] = _default_format,
key: str = None,
help: str = None,
*,
disabled: bool = False,
label_visibility: LabelVisibility = "visible",
) -> T | None:
if not options:
return None
options = list(options)
if not key:
key = md5_values("radio", label, options, help, label_visibility)
value = state.session_state.get(key)
if key not in state.session_state or value not in options:
value = options[0]
state.session_state.setdefault(key, value)
if label_visibility != "visible":
label = None
markdown(label)
for option in options:
if button(
format_func(option),
key=f"tab-{key}-{option}",
type="primary",
className="replicate-nav",
style={
"background": "black" if value == option else "white",
"color": "white" if value == option else "black",
},
disabled=disabled,
):
state.session_state[key] = value = option
state.experimental_rerun()
return value


def radio(
label: str,
options: typing.Sequence[T],
Expand Down
2 changes: 1 addition & 1 deletion recipes/QRCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def render_form_v2(self):
if st.session_state.get(key):
st.session_state[qr_code_source_key] = key
break
source = st.radio(
source = st.horizontal_radio(
"",
options=QrSources._member_names_,
key=qr_code_source_key,
Expand Down

0 comments on commit 33fe11a

Please sign in to comment.