plotly / plotly/plotly.R

Key variable returned as length 1 character from event_data('plotly_click')

未关闭
#1,708 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

Not sure if this is a bug or not, but I'm using plotly within a Shiny app. I'm using a geom_tile() heatmap type of graph and the user should be able to click a box which then triggers a follow-up database query. I followed the solution here: https://community.plot.ly/t/how-to-return-the-same-event-data-information-for-selected-points-even-after-modifying-the-data/5847/2

However, this doesn't seem to work for a geom_tile() click. I create a key variable by pasting the label and month of the clicked box together. The key is always returned as a length 1 character instead of returning the full string. Full reprex below:

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)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 R/Shiny reprex 开始,重点关注 plotly_click observer 中的 geom_tile() 和 event_data("plotly_click")。跟踪 tile 点击时变量 key 的传递方式,并将结果与预期的完整行名字符串进行核对,而不是与长度为 1 的 character 值核对。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。