我有一个闪亮的应用程序,使用rCharts中的highcharts库显示一些图表 .

在某些情况下,我在单个图表上有多个图表,这些图表是使用hPlot中的group选项创建的 .

我希望在单击图表时打印单个数据点的所有参数:x,y和组值 .

我附加代码以实现:

ui.r:

library(shiny)
library(rCharts)

shinyUI(bootstrapPage(
  showOutput("chart", "highcharts"),
  textOutput("Text")
))

server.r:

library(shiny)
library(rCharts)

data = data.frame(y = sample(c(1:100),100,replace = TRUE),x = sample(c(1:10),100,replace = TRUE),z = sample(c(1:2),100,replace = TRUE))

shinyServer(function(input, output) {


  output$Text = renderText({
    res = paste(input$click$x,input$click$y,input$click$z,sep = ",")
    return(res)
  })

  output$chart <- renderChart2({
    a <- rCharts:::Highcharts$new()
    a = hPlot(
      y ~ x,
      data = data,
      group = "z",
      type = "line"
    )

    a$plotOptions(
      line = list(
        cursor = "pointer",
        point = list(
          events = list(
            click = "#! function() {
                          Shiny.onInputChange('click', {
                            x: this.x,
                            y: this.y,
                            z: this.group
                          })
                        } !#"
          )
        )
      )
    )
    a$addParams(dom = "chart")
    return(a)
  })
})

当我点击某个数据点时,我只会在没有组变量的情况下将x和y坐标打印到屏幕上 .

可能是什么原因?

也许对group变量的调用不是this.group?

谢谢 .