我想在用户点击列高清图的栏中时检测到一些信息。我需要获取所单击栏的名称,并将其用作输入 我试图从条形图中获取值以用作数据框中的输入来过滤数据框架
// server.r
library("shiny")
library("highcharter")
library("dplyr")
library("purrr")
shinyServer(function(input, output, session) {
output$hcontainer <- renderHighchart({
canvasClickFunction <- JS("function(event) {Shiny.onInputChange('canvasClicked', [this.name, event.point.category]);}")
legendClickFunction <- JS("function(event) {Shiny.onInputChange('legendClicked', [this.name, event.target.visible]);}")
df <- data_frame(
name = c("Animals", "Fruits", "Cars"),
y = c(5, 2, 4),
drilldown = tolower(name)
)
ds <- list.parse3(df)
names(ds) <- NULL
str(ds)
hc <- highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "Basic drilldown") %>%
hc_xAxis(type = "category") %>%
hc_legend(enabled = FALSE) %>%
hc_plotOptions(
series = list(
boderWidth = 0,
dataLabels = list(enabled = TRUE),
events = list(click = canvasClickFunction, legendItemClick = legendClickFunction) click function is using here to get the values from bar high chart
) )%&gt;% hc_add_series( name = input $ canvasClicked [2], colorByPoint = TRUE, data = ds )
dfanny <- data_frame(
name = c("Cats","Dogs","Cows","Sheep","Pigs","Apple","Oranges","Toyota","Opel","Volkswage"),
name1=c("Animals","Fruits", "Cars","Animals", "Fruits", "Cars","Animals", "Fruits", "Cars","Cars"),
value = c(4,2,4, 3, 1, 2, 1,4, 2, 2)
)%>%filter(name1==input$canvasClicked[2])
input$canvasClicked[2](not getting the selected value)
##here getting error Result must have length 10, not 0
dfan<-data_frame(
name=dfanny$name,
value=dfanny$value
)
second_el_to_numeric <- function(ls){
map(ls, function(x){
x[[2]] <- as.numeric(x[[2]])
x
})
}
dsan <- second_el_to_numeric(list.parse2(dfan))
hc <- hc %>%
hc_drilldown(
allowPointDrilldown = TRUE,
series = list(
list(
id = "fruits",
data = dsan
)))
return(hc)
})
})
// ui.r
fluidPage(
h1("Highcharter EXAMPLE"),
fluidRow(
highchartOutput("hcontainer",height = "500px")
))