# Dependency

### Description

The Dependency object is usually not created directly but is returned when an event listener is set up. It contains the configuration data for the event listener, and can be used to set up additional event listeners that depend on the completion of the current event listener using .then(), .success(), and .failure().

### Example Usage

```python
import gradio as gr

with gr.Blocks() as demo: 
    first_textbox = gr.Textbox()
    second_textbox = gr.Textbox()
    button = gr.Button("Submit")

    dependency = button.click(lambda x: "Hello, " + x, first_textbox, second_textbox)
    dependency.success(lambda: gr.Info("Greeting successful"), None, None)
    dependency.failure(lambda: gr.Warning("Greeting failed"), None, None)

demo.launch()
```

### Demos

**chatbot_consecutive**

[See demo on Hugging Face Spaces](https://huggingface.co/spaces/gradio/chatbot_consecutive)

```python
import gradio as gr
import random
import time

with gr.Blocks() as demo:
    chatbot = gr.Chatbot()
    msg = gr.Textbox()
    clear = gr.Button("Clear")

    def user(user_message, history):
        return "", history + [{"role": "user", "content": user_message}]

    def bot(history):
        bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
        time.sleep(2)
        history.append({"role": "assistant", "content": bot_message})
        return history

    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )
    clear.click(lambda: None, None, chatbot, queue=False)

if __name__ == "__main__":
    demo.launch()
```

**blocks_chained_events**

[See demo on Hugging Face Spaces](https://huggingface.co/spaces/gradio/blocks_chained_events)

```python
import gradio as gr

def failure():
    raise gr.Error("This should fail!")

def exception():
    raise ValueError("Something went wrong")

def success():
    return True

def warning_fn():
    gr.Warning("This is a warning!")

def info_fn():
    gr.Info("This is some info")

with gr.Blocks() as demo:
    gr.Markdown("Used in E2E tests of success event trigger. The then event covered in chatbot E2E tests."
                " Also testing that the status modals show up.")
    with gr.Row():
        result = gr.Textbox(label="Result")
        result_2 = gr.Textbox(label="Consecutive Event")
        result_failure = gr.Textbox(label="Failure Event")
    with gr.Row():
        success_btn = gr.Button(value="Trigger Success")
        success_btn_2 = gr.Button(value="Trigger Consecutive Success")
        failure_btn = gr.Button(value="Trigger Failure")
        failure_exception = gr.Button(value="Trigger Failure With ValueError")
    with gr.Row():
        trigger_warning = gr.Button(value="Trigger Warning")
        trigger_info = gr.Button(value="Trigger Info")

        success_btn_2.click(success, None, None).success(lambda: "First Event Trigered", None, result).success(lambda: "Consecutive Event Triggered", None, result_2)
        success_event = success_btn.click(success, None, None)
        success_event.success(lambda: "Success event triggered", inputs=None, outputs=result)
        success_event.failure(lambda: "Should not be triggered", inputs=None, outputs=result_failure)
        failure_event = failure_btn.click(failure, None, None)
        failure_event.success(lambda: "Should not be triggered", inputs=None, outputs=result)
        failure_event.failure(lambda: "Failure event triggered", inputs=None, outputs=result_failure)
        failure_exception.click(exception, None, None)
        trigger_warning.click(warning_fn, None, None)
        trigger_info.click(info_fn, None, None)

if __name__ == "__main__":
    demo.launch(show_error=True)
```
