Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] set_input_hover for capturing mouseover events #47

Open
bklingen opened this issue Feb 16, 2021 · 1 comment
Open

Comments

@bklingen
Copy link

Hi,
the function set_input_click captures click events. I see that apexcharts.js also allows mouse-over events (called mouseMove).
Can this be implemented in the apexcharter package, so that one can e.g., retrieve the x- and y-coordinates when hovering over a point in a scatterplot?

Many thanks!

Bernhard

@pvictor
Copy link
Member

pvictor commented Feb 17, 2021

Hello,

I have to see how this event works with different types of charts before eventually integrate it like click event. Here's an example on how to use it currently:

library(shiny)
library(apexcharter)

ui <- fluidPage(
  tags$h3("Hover points information"),
  fluidRow(
    column(
      width = 6,
      apexchartOutput("chart")
    ),
    column(
      width = 6,
      verbatimTextOutput("res")
    )
  )
)

server <- function(input, output, session) {
  
  output$chart <- renderApexchart({
    apex(mtcars, aes(disp, qsec), type = "scatter") %>% 
      ax_chart(
        events = list(
          mouseMove = JS(
            "function(event, chartContext, config) {",
            "Shiny.setInputValue('myid', config.dataPointIndex);",
            "}"
          )
        )
      )
  })
  
  output$res <- renderPrint({
    req(input$myid)
    index <- input$myid + 1
    if (index > 0) {
      mtcars[index, ]
    }
  })
  
}

shinyApp(ui, server)

The value returned is the index of the data (starting from 0 in JavaScript), returning -1 if no point hovered.
This works here because there's only one serie of data, if several, you'll have to use seriesIndex too.

VIctor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants