How to combine {shiny}
, {ellmer}
and {htmltools}
to create AI applications
Dr. Albert Rapp
ShinyConf 2025
Senior Consultant
Content Creator
Freelancer
@rappa753
Dr. Albert Rapp
3mw.albert-rapp.de
info@albert-rapp.de
chat$stream('What is the meaning of life?')
## <generator/instance>
## function (self, private, user_turn, stream, echo)
## {
## while (!is.null(user_turn)) {
## for (chunk in private$submit_turns(user_turn, stream = stream,
## echo = echo)) {
## yield(chunk)
## }
## user_turn <- private$invoke_tools()
## }
## }
## <environment: 0x5acc0c634648>
10% off with code βRAPP10β
server <- function(input, output, session) {
chat <- ellmer::chat_claude('You are a helpful assistant')
observe({
## Logic after button click
insertUI(
'#chat_output',
where = 'beforeEnd',
ui = div(
class = 'chat_input',
input$textarea_chat_input
),
immediate = TRUE
)
}) |> bindEvent(input$send_text)
}
server <- function(input, output, session) {
chat <- ellmer::chat_claude('You are a helpful assistant')
observe({
## Logic after button click
insertUI(
'#chat_output',
where = 'beforeEnd',
ui = div(
class = 'chat_input',
input$textarea_chat_input
),
immediate = TRUE
)
insertUI(
'#chat_output',
where = 'beforeEnd',
ui = div(
class = 'chat_reply',
''
),
immediate = TRUE
)
}) |> bindEvent(input$send_text)
}
server <- function(input, output, session) {
chat <- ellmer::chat_claude('You are a helpful assistant')
observe({
## Logic after button click
insertUI(
'#chat_output',
where = 'beforeEnd',
ui = div(
class = 'chat_input',
input$textarea_chat_input
),
immediate = TRUE
)
insertUI(
'#chat_output',
where = 'beforeEnd',
ui = div(
class = 'chat_reply',
''
),
immediate = TRUE
)
stream <- chat$stream(input$textarea_chat_input)
coro::loop(for (chunk in stream) {
insertUI(
'.chat_reply:last',
where = 'beforeEnd',
ui = chunk,
immediate = TRUE
)
})
}) |> bindEvent(input$send_text)
}