Skip to content

Instantly share code, notes, and snippets.

@tcash21
Created February 25, 2020 03:05
Show Gist options
  • Save tcash21/f88b30809ba390b0591778f6d5812aa9 to your computer and use it in GitHub Desktop.
Save tcash21/f88b30809ba390b0591778f6d5812aa9 to your computer and use it in GitHub Desktop.
plotly_click + ggplot bug?
library(plotly)
library(shiny)
mtcars$key <- row.names(mtcars)
mtcars$col <- "black"
mtcars$name <- row.names(mtcars)
ui <- fluidPage(
plotlyOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlotly({
p <- ggplot(mtcars, aes(x = gear, y = name, key = key)) +
geom_tile(aes(fill = mpg, key = key))
ggplotly(p)
})
observeEvent(event_data("plotly_click"), {
click_data <- event_data("plotly_click")
print(click_data)
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment