jcheng5 / shinychat

Chat UI component for Shiny for R
Other
25 stars 1 forks source link

Can't easily append to a `chat_ui()` that is dynamically rendered #4

Open cpsievert opened 2 weeks ago

cpsievert commented 2 weeks ago

For example, one might expect this to work, but it doesn't

library(shiny)
library(bslib)

ui <- page_fluid(
  uiOutput("x")
)

server <- function(input, output, session) {

  chat_append("chat", "Hello, how can I help you?")

  output$x <- renderUI({
    chat_ui("chat")
  })

}

shinyApp(ui, server)
jcheng5 commented 1 week ago

Something feels weird to me about fixing this scenario by delaying all the chat_append actions until after flush. What if chat_ui took an argument for the initial set of messages, would that fix any reasonable scenario?

cpsievert commented 1 week ago

It would definitely help, and probably worth adding regardless of before/after flush. Just curious, are you mainly concerned about the potential for "unresponsive" chats? And/or something else?