Make C3 chart interactive

I'm using the C3 package and trying to make a pie chart that replicates the one found on the c3js.org website (https://c3js.org/samples/chart_pie.html).

The examples for the C3 package and on the c3js.org show something like the code below as working. Mine doesn't. Any ideas about what I need to do to replicate the behavior of the c3js.org example? I want the tooltip to pop up onclick, along with the change in colors of the pie slices. This feels like I am missing something very simple.

library(c3)

data.frame(sugar = 20,
           fat = 45,
           salt = 10) %>% 
    c3(onclick = htmlwidgets::JS('function (d, i) { console.log("onclick", d, i)}')) %>%
    
  c3_pie() 


1 Like

A %>% between c3() and c3_pie() ?

That was a typo. I've edited the original post. The %>% was not the problem. Thanks for catching that!

This is actually a recognised bug in the CRAN version 0.2 binary

apparently its fixed in later source, but one needs Rtools and to compile from source to get the benefit of this.

devtools::install_github("mrjoh3/c3")

p.p.s this has led me down the rabbithole of getting the latest rlang from source:

remotes::install_github("r-lib/rlang")

2 Likes

Looks like that fixed it! Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.