Skip to content

Dynamically generating components #4166

Answered by kleynjan
MuuXB asked this question in Q&A
Discussion options

You must be logged in to vote

How about:

from nicegui import ui

class Plug:
    def __init__(self):
        self.state = {}

    def add_row(self, key, value):
        self.state[key] = value
        self.build.refresh()

    @ui.refreshable
    def build(self):
        with ui.card():
            with ui.column():
                for key, val in self.state.items():
                    with ui.row():
                        ui.label(f'{key}: ').classes('font-bold')
                        ui.label(val)

@ui.page("/")
def index():
    plug = Plug()
    plug.build()        # type: ignore / pylance can't look past the decorator

    with ui.row():
        k = ui.input(label='key')
        v = ui.input(label='val')
    ui.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by MuuXB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants