Skip to content

z attribute no longer reported in event_data() when z is a matrix #1414

Closed
@cpsievert

Description

@cpsievert

Introduced in #1393. MRE of problem:

library(plotly)
library(shiny)

# cache computation of a correlation matrix
correlation <- round(cor(mtcars), 3)

ui <- fluidPage(
  mainPanel(
    plotlyOutput("heat")
  ),
  verbatimTextOutput("selection")
)

server <- function(input, output, session) {
  
  output$heat <- renderPlotly({
    plot_ly() %>%
      add_heatmap(
        x = names(mtcars), 
        y = names(mtcars), 
        z = correlation
      ) %>%
      layout(
        xaxis = list(title = ""), 
        yaxis = list(title = "")
      )
  })
  
  output$selection <- renderPrint({
    s <- event_data("plotly_click")
    if (length(s) == 0) {
      "Click on a cell in the heatmap to display a scatterplot"
    } else {
      cat("You selected: \n\n")
      as.list(s)
    }
  })
  
}

shinyApp(ui, server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions