Skip to content

"No method asJSON S3 class: R6" error when running example #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shaunalambe5 opened this issue May 15, 2025 · 4 comments
Closed

"No method asJSON S3 class: R6" error when running example #47

shaunalambe5 opened this issue May 15, 2025 · 4 comments

Comments

@shaunalambe5
Copy link

I tried replicating the example from ShinyConf (allowing LLM to update the front-end) but it returns an error - see attached. I followed the code from the demo and the python template online.

Code below:

library(ellmer)
library(shiny)
library(shinychat)
library(bslib)

ui <- bslib::page_sidebar(
  sliderInput("slider", label = "slider input", value = 50, min = 0, max = 100),
  sidebar = chat_ui("chat",
                    messages = "Welcome! Try asking me to <span class='suggestion'>update the slider to 80</span> "
  )
)

server <- function(input, output, session){
  
  update_slider <- function(value) {
    updateSliderInput(
      inputId = "slider",
      value = value
    )
  }
  
  chat <- chat_openai(
    model = "gpt-4o-mini",
    system_prompt = "You are a helpful assistant in the sidebar of a Shiny app.
        You have a tool available to you to update a slider in the main panel of the app."
  )
  
  update_slider |>
    tool(
      "Updates the slider input",
      value = type_integer()
    ) |>
    chat$register_tool()
  
  observeEvent(input$chat_user_input, {
    stream <- chat$stream_async(input$chat_user_input)
    chat_append("chat", stream)
  })
  
}

shinyApp(ui, server)
Image
@gadenbuie
Copy link
Contributor

Hi @shaunalambe5! It took me a bit to diagnose, but the error is happening because ellmer takes the return value of the tool and sends it back to the LLM. So instead of trying to send the return value of updateSliderInput() (which is somehow an R6 object that ellmer can't serialize), send a string back to the LLM saying that the action was taken:

  update_slider <- function(value) {
    updateSliderInput(
      inputId = "slider",
      value = value
    )
    "The value was updated."
  }

@gadenbuie
Copy link
Contributor

I've confirmed that the app crashing will be resolved in shinychat v0.2.0 (see #44), but the error message is still quite opaque.

Image

@shaunalambe5
Copy link
Author

Hi @gadenbuie, thanks for getting back so quickly. Adding the return string fixed it for me :) Thank you!

@gadenbuie
Copy link
Contributor

Great! Glad to hear that solved your problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants