-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Radio Input Component #166
Comments
You can update the state via REGIONS = [
"Africa",
"Americas",
"Asia",
"Europe",
"Oceania",
"All",
]
@solara.component
def RegionSelector(value, regions: list[str]):
region = solara.use_reactive(value)
with rv.RadioGroup(label="Region", v_model=region.value, on_v_model=region.set)):
for _region in regions:
rv.Radio(label=_region, value=_region)
@solara.component
def Page():
region = solara.use_reactive("Africa")
RegionSelector(region, REGIONS)
text = solara.Text(f"Current region: {region.value}")
rnd_btn = solara.Button("Randomize", on_click=lambda: region.set(random.choice(REGIONS))) |
Nice @Jhsmit Small tweak, you can drop the lambda:
|
Thanks @Jhsmit. Your solution works. I have modified the code a bit to be more generic and the ability to use A generic code for Radio: import solara
import reacton.ipyvuetify as rv
@solara.component
def Radio(label, value, values, on_value):
value_ = solara.use_reactive(value, on_value)
del value, on_value
with rv.RadioGroup(label=label, v_model=value_.value, on_v_model=value_.set):
for _value in values:
rv.Radio(label=_value, value=_value)
REGIONS = ["Africa",
"Americas",
"Asia",
"Europe",
"Oceania",
"All"]
@solara.component
def Page():
region, set_region = solara.use_state("Asia")
Radio(label="Select A Region", value=region,
on_value=set_region,values=REGIONS)
solara.Markdown(f"current region is {region}") Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
It would be great to have a Radio Button component for input selection. I can see
Radio
andRadioGroup
components inreacton.ipyvuetify
. But there are no examples about the state updates. Can anyone please let me know how can I modify the below snippet to have the radio input value in state?Thanks
The text was updated successfully, but these errors were encountered: