Skip to content

plotly R, Bar Chart restyle Direct Lables #1399

@djouallah

Description

@djouallah

I have this code that generate a bar chart with direct lables, I add a button to switch to another data, but how to update the direct labels data, sorry if it is not the right place, but I asked in the forum and stackoveflow forum and no reply, and I could not find any documentation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions