Chat UI component for Shiny for R.
(For Shiny for Python, see ui.Chat.)
You can install shinychat from CRAN with:
install.packages("shinychat")
Or, install the development version of shinychat from GitHub with:
# install.packages("pak")
::pak("jcheng5/shinychat") pak
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)
<- bslib::page_fluid(
ui chat_ui("chat")
)
<- function(input, output, session) {
server <- elmer::chat_openai(system_prompt = "You're a trickster who answers in riddles")
chat
observeEvent(input$chat_user_input, {
<- chat$stream_async(input$chat_user_input)
stream chat_append("chat", stream)
})
}
shinyApp(ui, server)