问题
I have a shiny application that shows some charts using the highcharts library in rCharts.
In some cases I have multiple graphs on a single chart which are created using the group option in hPlot.
I wish to print all the parameters of a single data point on a chart when clicking on it : the x,y and group values.
I'm attaching the code in order to achieve that:
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)
})
})
When I click on some data point i only get the x and y coordinates printed to the screen without the group variable.
What might be the cause?
maybe the call for the group variable is not this.group?
Thanks.
来源:https://stackoverflow.com/questions/27723555/print-group-name-on-clicking-a-data-point-in-a-hplot-chart-with-shiny