Introducing Gradio Clients

Watch
  1. Blocks Layout
  2. render

New to Gradio? Start here: Getting Started

See the Release History

render

@gr.render(inputs=···)
def hello(···):
   ... 

Description

The render decorator allows Gradio Blocks apps to have dynamic layouts, so that the components and event listeners in your app can change depending on custom logic. Attaching a @gr.render decorator to a function will cause the function to be re-run whenever the inputs are changed (or specified triggers are activated). The function contains the components and event listeners that will update based on the inputs.
The basic usage of @gr.render is as follows:
1. Create a function and attach the @gr.render decorator to it.
2. Add the input components to the inputs= argument of @gr.render, and create a corresponding argument in your function for each component.
3. Add all components inside the function that you want to update based on the inputs. Any event listeners that use these components should also be inside this function.

Example Usage

import gradio as gr

with gr.Blocks() as demo:
    input_text = gr.Textbox()

    @gr.render(inputs=input_text)
    def show_split(text):
        if len(text) == 0:
            gr.Markdown("## No Input Provided")
        else:
            for letter in text:
                with gr.Row():
                    text = gr.Textbox(letter)
                    btn = gr.Button("Clear")
                    btn.click(lambda: gr.Textbox(value=""), None, text)

Initialization

Parameters
inputs: list[Component] | Component | None
default = None

List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.

triggers: list[EventListenerCallable] | EventListenerCallable | None
default = None

List of triggers to listen to, e.g. [btn.click, number.change]. If None, will listen to changes to any inputs.

queue: bool
default = True

If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.

trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default = "always_last"

If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete.

concurrency_limit: int | None | Literal['default']
default = None

If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).

concurrency_id: str | None
default = None

If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.

Guides