我试图在点击列时获取类别名称。我已经实现了以下代码,但它似乎不起作用。我做错了什么?
library(shiny)
library(rCharts)
ui <- fluidPage(
showOutput("chart", lib="highcharts"),
textOutput("check")
)
server <- function(input, output){
output$chart <- renderChart2({
p1 <- rCharts:::Highcharts$new()
p1$chart(type = "column", width = 400, height = 400)
p1$title(text = "Iris")
p1$xAxis(categories = colnames(t(iris[1:4])), title = list(text = "Categories"))
p1$yAxis(title = list(text = "Length"))
p1$data(as.data.frame(iris[2,1:4]))
p1$plotOptions(events = list(click = "#! function() {Shiny.onInputChange('click', {
x: this.data[1]
})
} !#" ))
return(p1)
})
output$check <- renderText(paste0(input$hcClicked$x))
}
shinyApp(ui =ui, server = server)