How to add Onclick event to c3 chart in Shiny, R?

I want to add onclick event to c3.js chart in Shiny R. I`v read this article with c3 examples and try to do some simple app with print in console when clicked on chart. But in my case, onclick I have this error in console: ScreenShot
Could you, please, say what I do wrong?

   ##devtools::install_github("mrjoh3/c3")
    library(c3)
    library(shiny)

    shinyApp(
        ui = fluidPage(
            c3Output("c3test")
        ),
        server = function(input, output, session) {
          output$c3test <- renderC3({
            pie.chart <- data.frame(sugar=20,fat=45,salt=10) %>% 
              c3(onclick="function(d,element) {
                 console.log(d.id);
          }") %>% 
                    c3_donut()
        })
        }
    )

Thanks to the author of c3 library for shiny mrjoh3. He helped me find the right way, how to add JS function to c3 charts. Just need to put JS function into htmlwidgets::JS() function like here:

c3(data, onclick = htmlwidgets::JS('function(d, element){console.log(d.id)}'))

1 Like