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

Access persistent click/hover data in shiny, addresses #1401 #1409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Nov 15, 2018

See #1401 for more context

Review questions

  • Is it safe to remember event data by attaching an attribute to graphDiv in this way? Should try this out in conjunction with plotlyProxy().
  • Should we worry about emitting redundant data in the persistent case? Or should this be the responsibility of the user?
  • Should we worry that the persistent hover data isn't cleared when unhovering after a shift?

Testing notes

Install (devtools::install_github("ropensci/plotly#1409")), run this app, and make sure the event data is what you'd expect.

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("plot"),
  verbatimTextOutput("click"),
  verbatimTextOutput("shift_click"),
  verbatimTextOutput("hover"),
  verbatimTextOutput("shift_hover")
)

server <- function(input, output, session) {
  output$plot <- renderPlotly({
    plot_ly(x = 1:10, y = 1:10, key = LETTERS[1:10])
  })
  
  output$click <- renderPrint({
    d <- event_data("plotly_click")
    if (is.null(d)) "Transient click data" else d
  })
  output$shift_click <- renderPrint({
    d <- event_data("plotly_click_persist_on_shift")
    if (is.null(d)) "Persistent click data" else d
  })
  output$hover <- renderPrint({
    d <- event_data("plotly_hover")
    if (is.null(d)) "Transient hover data" else d
  })
  output$shift_hover <- renderPrint({
    d <- event_data("plotly_hover_persist_on_shift")
    if (is.null(d)) "Persistent hover data" else d
  })
}

shinyApp(ui, server)

@trafficonese
Copy link

Shouldn't a doubleclick clear the Shift selections?
Now the selection is only cleared, by clicking a new point/bar.

It also doesnt always reflect the highlighted elements, as Shift must be pressed already when clicking the first element. The "usual" behaviour would be to click the first without Shift and then to add more into the selection, hold Shift and click another point which will be added to the current selection.

The Box/Lasso-selection behave like the "usual" way.

Otherwise nice work 👍

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

Successfully merging this pull request may close these issues.

None yet

2 participants