Skip to contents

Creates a greeting object for use with chat_ui() or chat_set_greeting(). A greeting is displayed when the chat first loads and is dismissed when the user sends their first message.

Usage

chat_greeting(
  content,
  ...,
  persistent = FALSE,
  dismissible = lifecycle::deprecated()
)

Arguments

content

The greeting content. Can be:

...

These dots are for future extensions and must be empty.

persistent

Whether the greeting persists after the user sends a message. Defaults to FALSE, meaning the greeting is dismissed when the user sends their first message.

dismissible

[Deprecated] Renamed to persistent with an inverted value. dismissible = FALSE is equivalent to persistent = TRUE.

Value

An S3 object of class "chat_greeting".

Patterns

Persistent greeting (stays visible after the user sends a message):

chat_greeting("Please read our [terms of service](https://example.com).", persistent = TRUE)

Greeting with suggestion cards (clickable chips that fill the input):

chat_greeting(paste(
  "## Welcome!\n\n",
  "Try one of these:\n\n",
  '<span class="suggestion">Summarize my data</span>\n',
  '<span class="suggestion">Create a plot</span>\n',
  '<span class="suggestion">Explain this code</span>'
))

Greeting with HTML tags (Shiny inputs/outputs):

chat_greeting(htmltools::tagList(
  htmltools::h2("Welcome!"),
  shiny::selectInput("model", "Choose a model:", c("gpt-4o", "claude-3"))
))

Examples

if (FALSE) { # interactive()
library(shiny)
library(bslib)
library(shinychat)

ui <- page_fillable(
  chat_ui(
    "chat",
    greeting = chat_greeting("## Welcome!\n\nHow can I help you today?")
  )
)

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

shinyApp(ui, server)
}