plotly: Updating data with dropdown selection

前端 未结 1 630
忘了有多久
忘了有多久 2020-12-16 05:30

I am not sure if this is possible, but here is what I would like to do. I would like to update the data in a plotly plot by selecting from a dropdown menu.

1条回答
  •  隐瞒了意图╮
    2020-12-16 06:05

    Is this what you were after?

    require(plotly)
    df <- data.frame(x = runif(200), y = runif(200), z = runif(200))
    p <- plot_ly(df, x = ~x, y = ~y, mode = "markers", name = "A", visible = T) %>%
    layout(
      title = "Drop down menus - Styling",
      xaxis = list(domain = c(0.1, 1)),
      yaxis = list(title = "y"),
      updatemenus = list(
        list(
          y = 0.7,
          buttons = list(
            list(method = "restyle",
                 args = list("y", list(df$y)),  # put it in a list
                 label = "Show A"),
            list(method = "restyle",
                 args = list("y", list(df$z)),  # put it in a list
                 label = "Show B")))
    ))
    p
    

    0 讨论(0)
提交回复
热议问题