I'm trying to show a radio button with the options argument being a dict, then changing that dict in a function and trying to update the radio button for it to show the new option.
The code for this is the following:
from nicegui import ui
class RecipeSelector:
def __init__(self,initval):
self.value = initval
self.name = 'Recipeselector'
selectedOption = RecipeSelector('1')
optionsDict = {'1': 'Opt1', '2': 'Opt2'}
async def UpdateOptions():
result = await suredialog
if result == 'Yes':
optionsDict = {'1': 'Opt1', '2': 'Opt2'} #<- This line is the issue.
index=int(max(optionsDict.keys()))+1
optionsDict[str(index)] = 'Opt'+str(index)
optionSelector.update()
ui.notify("Radio Updated")
else:
ui.notify(f'You chose {result}')
with ui.dialog() as suredialog, ui.card():
ui.label('Are you sure?')
with ui.row():
ui.button('Yes', on_click=lambda: suredialog.submit('Yes'))
ui.button('No', on_click=lambda: suredialog.submit('No'))
optionSelector = ui.radio(optionsDict).bind_value(selectedOption, 'value')
ui.button('New Option', on_click=UpdateOptions)
ui.run()