I am having problems integrating this chat feature into a modular shiny app. Using the chat_ui example and some slight modifications to make it modular generate this error. I think it has something to do with R not being able to find input$chat_user_input but I don't know how to fix that since it's all abstracted inside the chat_ui function.
Error in paste(namespace,collapse=ns.sep): cannot coerce type closure to vector of type character
Link to shinychat page: shinychat
library(shiny)
library(bslib)
library(shinychat)
chat_ui <- function(id){
ns <- NS(id)
page_fillable(
chat_ui(ns("chat"), fill = TRUE)
)
}
chat_server <- function(input, output, session) {
moduleServer(id, function(input,output,session) {
observeEvent(input$chat_user_input, {
# In a real app, this would call out to a chat model or API,
# perhaps using the 'elmer' package.
response <- paste0(
"You said:\n\n",
"<blockquote>",
htmltools::htmlEscape(input$chat_user_input),
"</blockquote>"
)
chat_append("chat", response)
})
})
}
I am having problems integrating this chat feature into a modular shiny app. Using the chat_ui example and some slight modifications to make it modular generate this error. I think it has something to do with R not being able to find input$chat_user_input but I don't know how to fix that since it's all abstracted inside the chat_ui function.
Error in paste(namespace,collapse=ns.sep): cannot coerce type closure to vector of type character
Link to shinychat page: shinychat
library(shiny)
library(bslib)
library(shinychat)
chat_ui <- function(id){
ns <- NS(id)
page_fillable(
chat_ui(ns("chat"), fill = TRUE)
)
}
chat_server <- function(input, output, session) {
moduleServer(id, function(input,output,session) {
observeEvent(input$chat_user_input, {
# In a real app, this would call out to a chat model or API,
# perhaps using the 'elmer' package.
response <- paste0(
"You said:\n\n",
"<blockquote>",
htmltools::htmlEscape(input$chat_user_input),
"</blockquote>"
)
chat_append("chat", response)
})
})
}
Share
Improve this question
edited Mar 10 at 19:05
Jan
10.2k6 gold badges21 silver badges33 bronze badges
asked Mar 10 at 14:18
JoshJosh
2,0123 gold badges18 silver badges22 bronze badges
2
|
1 Answer
Reset to default 3The main issue is that you define the ui
function with name chat_ui
, but this is also the name of the shinychat
function chat_ui
. This is most probably also the reason why the example from the webpage is not working for you (as per your comment), and if you restart your session without overwriting the function, it should work.
Below is a working example where I renamed things such that there are no conflicts and where I made some adjustments such that there are no namespace issues within the server.
library(shiny)
library(bslib)
library(shinychat)
my_chat_ui <- function(id){
ns <- NS(id)
page_fillable(
chat_ui(
ns("my_chat"),
fill = TRUE
)
)
}
my_chat_server <- function(id) {
moduleServer(
id,
function(input, output, session) {
observeEvent(input$my_chat_user_input, {
# In a real app, this would call out to a chat model or API,
# perhaps using the 'elmer' package.
response <- paste0(
"You said:\n\n",
"<blockquote>",
htmltools::htmlEscape(input$my_chat_user_input),
"</blockquote>"
)
ns <- NS(id)
chat_append(ns("my_chat"), response)
})
}
)
}
server <- function(input, output, session) {
my_chat_server("chat")
}
shinyApp(ui = my_chat_ui("chat"), server = server)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744842326a4596632.html
chat_ui("chat", fill = TRUE)
? I think the chat objects use black magic to find each other. – Michael Dewar Commented Mar 10 at 15:15