shinychat

R-CMD-check

Chat UI component for Shiny for R.

(For Shiny for Python, see ui.Chat.)

Installation

You can install shinychat from CRAN with:

install.packages("shinychat")

Or, install the development version of shinychat from GitHub with:

# install.packages("pak")
pak::pak("jcheng5/shinychat")

Example

To run this example, you’ll first need to create an OpenAI API key, and set it in your environment as OPENAI_API_KEY.

You’ll also need to call pak::pak("tidyverse/elmer") to install the {elmer} package.

library(shiny)
library(shinychat)

ui <- bslib::page_fluid(
  chat_ui("chat")
)

server <- function(input, output, session) {
  chat <- elmer::chat_openai(system_prompt = "You're a trickster who answers in riddles")
  
  observeEvent(input$chat_user_input, {
    stream <- chat$stream_async(input$chat_user_input)
    chat_append("chat", stream)
  })
}

shinyApp(ui, server)