% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/chat.R
\name{chat_clear}
\alias{chat_clear}
\title{Clear all messages from a chat control}
\usage{
chat_clear(id, greeting = FALSE, session = getDefaultReactiveDomain())
}
\arguments{
\item{id}{The ID of the chat element}

\item{greeting}{If \code{TRUE}, also clears the greeting. When the greeting is
cleared, \code{greeting_requested} will fire again (if the chat is visible),
allowing the server to generate a new greeting.}

\item{session}{The Shiny session object}
}
\description{
Removes all messages from the chat UI. Set \code{greeting = TRUE} to also
clear the greeting, which re-triggers \code{greeting_requested} (see the
\strong{Greeting} section in \code{\link[=chat_ui]{chat_ui()}}).
}
\examples{
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf}

library(shiny)
library(bslib)

ui <- page_fillable(
  chat_ui("chat", fill = TRUE),
  actionButton("clear", "Clear chat")
)

server <- function(input, output, session) {
  observeEvent(input$clear, {
    chat_clear("chat")
  })

  observeEvent(input$chat_user_input, {
    response <- paste0("You said: ", input$chat_user_input)
    chat_append("chat", response)
  })
}

shinyApp(ui, server)
\dontshow{\}) # examplesIf}
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf}

library(shiny)
library(bslib)
library(shinychat)

# Regenerate greeting on clear
ui <- page_fillable(
  chat_ui("chat"),
  actionButton("new_chat", "New chat")
)

server <- function(input, output, session) {
  observeEvent(input$chat_greeting_requested, {
    chat_set_greeting("chat", "## Welcome!\n\nHow can I help?")
  })

  observeEvent(input$new_chat, {
    # Clearing with greeting = TRUE triggers greeting_requested again
    chat_clear("chat", greeting = TRUE)
  })

  observeEvent(input$chat_user_input, {
    chat_append("chat", paste0("You said: ", input$chat_user_input))
  })
}

shinyApp(ui, server)
\dontshow{\}) # examplesIf}
}
