Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在highchart列r闪亮绘图中检测条形图中的多个剪辑_Javascript_Jquery_R_Highcharts_Shiny - Fatal编程技术网

Javascript 如何在highchart列r闪亮绘图中检测条形图中的多个剪辑

Javascript 如何在highchart列r闪亮绘图中检测条形图中的多个剪辑,javascript,jquery,r,highcharts,shiny,Javascript,Jquery,R,Highcharts,Shiny,当我单击以禁用列,然后立即单击以启用列时,我无法检测到第二个事件。如何检测一个列或图例被禁用和启用(反之亦然),中间没有任何其他不同的事件? 另一个问题是:是否可能检测到在绘图背景上的单击 library("shiny") library("highcharter") ui <- shinyUI( fluidPage( column(width = 8, highchartOutput("hcontainer", height = "500px")), column(

当我单击以禁用列,然后立即单击以启用列时,我无法检测到第二个事件。如何检测一个列或图例被禁用和启用(反之亦然),中间没有任何其他不同的事件?

另一个问题是:是否可能检测到在绘图背景上的单击

library("shiny")
library("highcharter")

ui <- shinyUI(
  fluidPage(
    column(width = 8, highchartOutput("hcontainer", height = "500px")),
    column(width = 4, textOutput("text"))
  )
)

server <- function(input, output) {      

  a <- data.frame(b = LETTERS[1:10], c = 11:20, d = 21:30, e = 31:40)

  output$hcontainer <- renderHighchart({      

    canvasClickFunction <- JS("function(event) {Shiny.onInputChange('canvasClicked', [this.name, event.point.category]);}")
    legendClickFunction <- JS("function(event) {Shiny.onInputChange('legendClicked', this.name);}")

    highchart() %>% 
      hc_xAxis(categories = a$b) %>% 
      hc_add_serie(name = "c", data = a$c) %>%
      hc_add_serie(name = "d", data = a$d) %>% 
      hc_add_serie(name = "e", data = a$e) %>%
      hc_plotOptions(series = list(stacking = FALSE, events = list(click = canvasClickFunction, legendItemClick = legendClickFunction))) %>%
      hc_chart(type = "column")

  })      

  makeReactiveBinding("outputText")

  observeEvent(input$canvasClicked, {
    outputText <<- paste0("You clicked on series ", input$canvasClicked[1], " and the bar you clicked was from category ", input$canvasClicked[2], ".") 
  })
库(“闪亮”)
图书馆(“高宪章”)
ui%
hc_图表(type=“column”)
})      
makeReactiveBinding(“输出文本”)
observeEvent(输入$canvasClicked{

outputText将click events与Shiny一起使用时,有时需要再次提醒具有相同值的相同事件。是Shiny固有的,只有值的更改才会被提醒,而reactive仅对更改做出反应。 一个简单的解决方法是,不仅发送所需的值,还发送一个随机数或当前时间。每次都会更改

因此,在多次单击同一系列时,图例单击的一种可能性是将JS函数更改为

Shiny.onInputChange('legendClick', [this.name, Math.random()]);
在代码中,使用
input$legend单击[1]
访问序列名称

但是,在您的情况下,您还需要获取图例项的状态。这当然是一个随着单击而改变的东西。因此,如果我们将其与名称一起发送,输入值将始终改变。因此,不需要上面的一般建议。图例状态存储在
事件
下的
事件.target.visible
。在那里,y单击时,您可以查看单击的系列的可见性状态。这意味着在获得单击事件后,您的可见性状态与单击的系列相反

代码如下:

library("shiny")
library("highcharter")

ui <- shinyUI(
  fluidPage(
    column(width = 8, highchartOutput("hcontainer", height = "500px")),
    column(width = 4, textOutput("text"))
  )
)

server <- function(input, output) {      

  a <- data.frame(b = LETTERS[1:10], c = 11:20, d = 21:30, e = 31:40)

  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]);}")

    highchart() %>% 
      hc_xAxis(categories = a$b) %>% 
      hc_add_serie(name = "c", data = a$c) %>%
      hc_add_serie(name = "d", data = a$d) %>% 
      hc_add_serie(name = "e", data = a$e) %>%
      hc_plotOptions(series = list(stacking = FALSE, events = list(click = canvasClickFunction, legendItemClick = legendClickFunction))) %>%
      hc_chart(type = "column")

  })      

  makeReactiveBinding("outputText")

  observeEvent(input$canvasClicked, {
    outputText <<- paste0("You clicked on series ", input$canvasClicked[1], " and the bar you clicked was from category ", input$canvasClicked[2], ".") 
  })

  observeEvent(input$legendClicked, {
    # Visibility of target. When deselecting, the target was visible at the moment of click.
    seriesStatus <- switch(input$legendClicked[2], "FALSE" = "visible", "TRUE" = "invisible")
    outputText <<- paste0("You clicked into the legend and selected series ", input$legendClicked[1], " and this Series is now ", seriesStatus, ".")
  })

  output$text <- renderText({
    outputText      
  })
}

shinyApp(ui, server) 
库(“闪亮”)
图书馆(“高宪章”)
ui%
hc_图表(type=“column”)
})      
makeReactiveBinding(“输出文本”)
observeEvent(输入$canvasClicked{

outputText将click events与Shiny一起使用时,有时需要再次提醒具有相同值的相同事件。是Shiny固有的,只有值的更改才会被提醒,而reactive仅对更改做出反应。 一个简单的解决方法是,不仅发送所需的值,还发送一个随机数或当前时间。每次都会更改

因此,在多次单击同一系列时,图例单击的一种可能性是将JS函数更改为

Shiny.onInputChange('legendClick', [this.name, Math.random()]);
在代码中,使用
input$legend单击[1]
访问序列名称

但是,在您的情况下,您还需要获取图例项的状态。这当然是一个随着单击而改变的东西。因此,如果我们将其与名称一起发送,输入值将始终改变。因此,不需要上面的一般建议。图例状态存储在
事件
下的
事件.target.visible
。在那里,y单击时,您可以查看单击的系列的可见性状态。这意味着在获得单击事件后,您的可见性状态与单击的系列相反

代码如下:

library("shiny")
library("highcharter")

ui <- shinyUI(
  fluidPage(
    column(width = 8, highchartOutput("hcontainer", height = "500px")),
    column(width = 4, textOutput("text"))
  )
)

server <- function(input, output) {      

  a <- data.frame(b = LETTERS[1:10], c = 11:20, d = 21:30, e = 31:40)

  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]);}")

    highchart() %>% 
      hc_xAxis(categories = a$b) %>% 
      hc_add_serie(name = "c", data = a$c) %>%
      hc_add_serie(name = "d", data = a$d) %>% 
      hc_add_serie(name = "e", data = a$e) %>%
      hc_plotOptions(series = list(stacking = FALSE, events = list(click = canvasClickFunction, legendItemClick = legendClickFunction))) %>%
      hc_chart(type = "column")

  })      

  makeReactiveBinding("outputText")

  observeEvent(input$canvasClicked, {
    outputText <<- paste0("You clicked on series ", input$canvasClicked[1], " and the bar you clicked was from category ", input$canvasClicked[2], ".") 
  })

  observeEvent(input$legendClicked, {
    # Visibility of target. When deselecting, the target was visible at the moment of click.
    seriesStatus <- switch(input$legendClicked[2], "FALSE" = "visible", "TRUE" = "invisible")
    outputText <<- paste0("You clicked into the legend and selected series ", input$legendClicked[1], " and this Series is now ", seriesStatus, ".")
  })

  output$text <- renderText({
    outputText      
  })
}

shinyApp(ui, server) 
库(“闪亮”)
图书馆(“高宪章”)
ui%
hc_图表(type=“column”)
})      
makeReactiveBinding(“输出文本”)
observeEvent(输入$canvasClicked{
输出文本