如何将 Onclick 事件添加到 Shiny, R 中的 c3 图表?
How to add Onclick event to c3 chart in Shiny, R?
我想将 onclick 事件添加到 Shiny R 中的 c3.js 图表。我读了这个 article with c3 examples 并尝试在单击图表时在控制台中打印一些简单的应用程序。
但就我而言,onclick 我有
this error in console。你能说说我做错了什么吗?
##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()
})
}
)
感谢 c3 库的作者 shiny mrjoh3。他帮助我找到了正确的方法,如何将 JS 功能添加到 c3 图表。只需要将 JS 函数放入 htmlwidgets::JS() 函数中,如下所示:
c3(data, onclick = htmlwidgets::JS('function(d, element){console.log(d.id)}'))
我想将 onclick 事件添加到 Shiny R 中的 c3.js 图表。我读了这个 article with c3 examples 并尝试在单击图表时在控制台中打印一些简单的应用程序。 但就我而言,onclick 我有 this error in console。你能说说我做错了什么吗?
##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()
})
}
)
感谢 c3 库的作者 shiny mrjoh3。他帮助我找到了正确的方法,如何将 JS 功能添加到 c3 图表。只需要将 JS 函数放入 htmlwidgets::JS() 函数中,如下所示:
c3(data, onclick = htmlwidgets::JS('function(d, element){console.log(d.id)}'))