Learn R Programming

shinychat

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)

Copy Link

Version

Install

install.packages('shinychat')

Monthly Downloads

1,529

Version

0.1.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Cheng

Last Published

December 18th, 2024

Functions in shinychat (0.1.1)

chat_append

Append an assistant response (or user message) to a chat control
chat_append_message

Low-level function to append a message to a chat control
chat_ui

Create a chat UI element