ChatAreaInput#

Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).


import panel as pn

pn.extension()

The ChatAreaInput inherits from TextAreaInput, allowing entering any multiline string using a text input box, with the ability to click the “Enter” key to submit the message.

Unlike TextAreaInput, the ChatAreaInput defaults to auto_grow=True and max_rows=10, and the value is not synced to the server until the “Enter” key is pressed so watch value_input if you need to access what’s currently available in the text input box.

Lines are joined with the newline character \n.

It’s primary purpose is use within the ChatInterface for a high-level, easy to use, ChatGPT like interface.

Chat Design Specification

Parameters:#

For layout and styling related parameters see the customization user guide.

Core#

  • disabled_enter (bool): If True, the enter key will not submit the message (clear the value).

  • value (str): The value when the “Enter” key is pressed. Only to be used with watch or bind because the value resets to "" after the “Enter” key is pressed; use value_input instead to access what’s currently available in the text input box.

  • value_input (str): The current value updated on every key press.

Display#

  • auto_grow (boolean, default=True): Whether the TextArea should automatically grow in height to fit the content.

  • cols (int, default=2): The number of columns in the text input field.

  • disabled (boolean, default=False): Whether the widget is editable

  • max_length (int, default=5000): Max character length of the input field. Defaults to 5000

  • max_rows (int, default=10): The maximum number of rows in the text input field when auto_grow=True.

  • name (str): The title of the widget

  • placeholder (str): A placeholder string displayed when no value is entered

  • rows (int, default=2): The number of rows in the text input field.

  • resizable (boolean | str, default=’both’): Whether the layout is interactively resizable, and if so in which dimensions: width, height, or both.


Basics#

To submit a message, press the Enter key.

pn.chat.ChatAreaInput(placeholder="Type something, and press Enter to clear!")

The ChatAreaInput is useful alongside pn.bind or param.depends.

def output(value):
    return f"Submitted: {value}"

chat_area_input = pn.chat.ChatAreaInput(placeholder="Type something, and press Enter to submit!")
output_markdown = pn.bind(output, chat_area_input.param.value)
pn.Row(chat_area_input, output_markdown)

To see what’s currently typed in, use value_input instead because value will be "" besides during submission.

chat_area_input = pn.chat.ChatAreaInput(placeholder="Type something, leave it, and run the next cell")
chat_area_input
print(chat_area_input.value_input, chat_area_input.value)
 

Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).