plotly / plotly/plotly.R

Updatemenu buttons is not working properly, graph disappearing

未关闭
#2,079 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Hi,
I am trying to add buttons in plotly R by using updatemenus option to change xaxis range. I am using category array. I have 10 variable in x-axis as given below. When I use "7A" instead of "1234500" as variable at x-axis, updatemenus is working properly and it is changing graph with selected range. If I use "1234500" instead of "7A", graph is disappearing after changing range at menu. I could not find the reason.

I hope someone can help what is really wrong

Here is as an example code:

x<-c("1A","2A","3A","4A","5A","6A","1234500","1234501","1234502","1234503")
random_y <- sample(1:10, 10, replace=T)
random_z <- sample(1:10, 10, replace=T)
random_w <- sample(1:10, 10, replace=T)
data <- data.frame(x, random_y, random_z, random_w)

y<-ceiling(length(data$x)/3)
buttons<-vector(mode = "list", length = y)

for(i in 1:y){
  lower<-(i-1)*3
  upper<-i*3-1
    
 a<- list(
      label = as.character(i*3),
      method = "update",
      args = list(list(visible = c(T,T,T)), 
                  list(xaxis = list(range = c(lower, upper))))
      )
 buttons[[i]]<-a
}

updatemenus <- list(
  list(
    active = -1,
    type = 'dropdown',
    direction = "down",
    buttons = buttons
  )
)

fig <- plot_ly(data, x = ~x, y = ~random_y, type = 'bar') %>%
  add_trace(y = ~random_z)%>%
  add_trace(y = ~random_w)%>%
  layout(barmode = 'stack', xaxis = list(categoryorder = "array", categoryarray = ~x, range = c(0,10)),updatemenus = updatemenus
  )

fig

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用 plot_ly、add_trace、layout 和 updatemenus 配置重现所提供的 R 示例,比较类别值 "7A" 和 "1234500"。跟踪 xaxis 范围更新如何应用于分类轴;完成的标准是下拉菜单更改所选范围,同时图表不会消失。

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

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

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