posit-dev / posit-dev/shinychat
Allow onclick HTML elements in append_chat
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 139
- Forks
- 28
- Avg merge
- 23h 44m
- Merged PRs (30d)
- 50
Description
I have a shiny app where I use shinychat as a frontend for a RAG system. As I want to display sources to the users with nice UX, I would create button links that set some JS value using Shiny.setInputValue(), which is picked up and the appropriate source is rendered elsewhere.
The problem is that somehow somewhere shinychat swallows the onclick element:
library(shiny)
# create sample content
sample_content <- span(
"This is the sample source content.",
tags$button(
class = "btn btn-sm btn-link",
onclick = "Shiny.setInputValue('from_js', {p: 1, v: Math.random()})",
"Sample from Page 1"
)
)
ui <- bslib::page_fillable(
bslib::layout_columns(
bslib::card(
bslib::card_header("Here it is rendered with onclick => works"),
sample_content
),
bslib::card(
bslib::card_header("Here it is rendered with shinychat::chat_append => does not work, no onlclick!"),
shinychat::chat_ui("out")
)
)
)
server <- function(input, output, session) {
shinychat::chat_append(
"out",
sample_content,
session = session
)
# see if there are any inputs sent from the UI
shiny::observe({
print("From JS:")
print(input$from_js)
cat("===========\n")
})
}
shinyApp(ui, server)
When I click on the "raw HTML" button (left side), I see something like this:
[1] "From JS:"
$p
[1] 1
$v
[1] 0.3141059
===========
[1] "From JS:"
$p
[1] 1
$v
[1] 0.6320509
when I click on the shinychat renderd button (right side) nothing is shown, when I inspect the button, I see this HTML source code without the onclick functionality
<button class="btn btn-sm btn-link">Sample from Page 1</button>
is there any way for me as a user to change this behavior or is there another workaround to setting some values from the output of the chat system?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the shinychat::chat_append entry point and compare its rendered HTML with the direct UI rendering shown in the report. Reproduce the example, inspect where the onclick attribute is removed, and verify that appended button elements preserve the handler without breaking existing chat rendering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100