plotly R гистограмма обновления прямых меток данных - PullRequest
0 голосов
/ 16 октября 2018

У меня есть этот код, который генерирует гистограмму с прямыми метками, я добавляю кнопку для переключения на другие данные, но как обновить данные прямых меток

library(plotly)


chart <- structure(list(Date3 = structure(c(17805, 17806, 17807, 17808
), class = "Date"), Installed_qty_piling = c(9000, 1, 741, 72), Installed_qty_piling_Delivery = c(2592, 
                                                                                                  250, 33, 24)), row.names = c(NA, -4L), class = c("tbl_df", 
                                                                                                                                                   "tbl", "data.frame"))




p <- plot_ly(chart, x = ~Date3, y = ~Installed_qty_piling,text=~Installed_qty_piling,textposition = 'auto', type = "bar",  name = "A", visible = T) %>%
  layout(
    title = "qty installed",
    yaxis = list(title = "qty"),
    updatemenus = list(
      list(
        y = 100,
        buttons = list(
          list(method = "restyle",
               args = list("y", list(chart$Installed_qty_piling)),  # put it in a list
               label = "piling"),
          list(method = "restyle",
               args = list("y", list(chart$Installed_qty_piling_Delivery)),  # put it in a list
               label = "piling Delivery")))
    ))
p

1 Ответ

0 голосов
/ 20 ноября 2018

да, я нашел ответ где-то еще, нужно обновить текст тоже

library(plotly)


chart <- structure(list(Date3 = structure(c(17805, 17806, 17807, 17808
), class = "Date"), Installed_qty_piling = c(9000, 1, 741, 72), 
Installed_qty_piling_Delivery = c(2592, 

250, 33, 24)), row.names = c(NA, -4L), class = c("tbl_df", 

"tbl", "data.frame"))
plot_ly(chart, x = ~Date3, y = 
~Installed_qty_piling,text=~Installed_qty_piling,textposition = 'auto', type = "bar",  
name = "A", visible = T) %>%
layout(
   title = "qty installed",
   yaxis = list(title = "qty"),
updatemenus = list(
  list(
    y = 100,
    buttons = list(
      list(method = "restyle",
           args = list(list(y = list(chart$Installed_qty_piling), text = list(chart$Installed_qty_piling))),
           label = "piling"),
      list(method = "restyle",
           args = list(list(y = list(chart$Installed_qty_piling_Delivery), text = list(chart$Installed_qty_piling_Delivery))), 
           label = "piling Delivery")))
)

)

...