plotly / plotly/plotly.R

Empty event payload for plotly_selected when using ggplotly on geom_tile

Open
#1,820 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

In the example provided below, the heatmap is selectable on the x but the corresponding event payload is empty.

Expected: The selection should be part of the event payload. This works for other plots, e.g. see commented out histogram example in the provided code.

# Source https://rdrr.io/cran/plotly/src/inst/examples/shiny/event_data/app.R

library(plotly)
library(nycflights13)
library(shiny)
library(dplyr)
library(lubridate)

flights = flights %>% mutate(departure = make_datetime(year, month, day, hour, minute))

ui <- fluidPage(
radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
plotlyOutput("plot"),
verbatimTextOutput("brushing"),
)

server <- function(input, output, session) {


    output$plot <- renderPlotly({
        p <- if (identical(input$plotType, "ggplotly")) {
            ## works and gives correct results
            # ggplotly(ggplot(flights, aes(x = departure)) + geom_histogram())
            ## gives empty event data
            ggplotly(ggplot(head(flights, 10000), aes(x = departure, carrier, fill=arr_time)) + geom_tile())
        } else {
            plot_ly(mtcars, x = ~mpg, y = ~wt, customdata = nothing)
        }
        p %>%
            layout(dragmode = "select") %>%
            #  see https://webinars.cpsievert.me/20180220/#13
            event_register("plotly_selected")
    })

    observeEvent(event_data("plotly_selected"), {
        d <- event_data("plotly_selected")
      print("caught event from here as well")
      print(paste(str(d)))
    })

}

shinyApp(ui, server)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible Shiny example from inst/examples/shiny/event_data/app.R and compare the ggplotly geom_tile case with the working histogram and plot_ly branches. Trace event_data("plotly_selected") and event_register("plotly_selected"); done means the tile selection returns a non-empty payload like the other selectable plots.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.