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.
Arguments
- content
The greeting content. Can be:
A string, interpreted as markdown.
An
htmltools::HTML()object, rendered as raw HTML.An htmltools tag or
htmltools::tagList(), including Shiny inputs/outputs.A generator or promise (only valid when used with
chat_set_greeting()).
- dismissible
Whether the greeting is automatically dismissed when the user sends a message. Defaults to
TRUE.
Patterns
Non-dismissible greeting (stays visible after the user sends a message):
chat_greeting("Please read our [terms of service](https://example.com).", dismissible = FALSE)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)
}