在Plotly下拉菜单

时间:2017-10-30 12:32:34

标签: r drop-down-menu plotly

我正在尝试在this情节图中添加一个下拉菜单。代码是:

library(plotly)
library(readxl)
Sys.setenv("plotly_username"="xxx")
Sys.setenv("plotly_api_key"="xxx")
df <- read_excel("From\\a\\certain\\location.xlsx")
k = (df$keyword=="alpha")
j = (df$keyword=="beta")

# give state boundaries a white border
l <- list(color = toRGB("grey"), width = 0.5)
# specify some map projection/options
g <- list(
  showframe = FALSE,
  showcoastlines = FALSE,
  projection = list(type='Mercator')
)

df2 = df
p <- plot_geo(df2, locationmode = 'country names') %>%
  add_trace(
    z = ~hits, locations = ~location,
    color = ~hits, colors = 'Blues',marker=list(line=l)
  ) %>%
  colorbar(title = "Hits") %>%
  layout(
    title = 'For Addiction',
    geo = g
  )
p <-p %>% layout(
  updatemenus = list(
    list(
      buttons = list(
        list(method = "restyle",
             args = list("df2",list(df[k,])),
             label = "alpha"),
        list(method = "restyle",
             args = list("df2",list(df[j,])),
             label = "beta")))
  ))

# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started

chart_link = plotly_POST(p, filename="Example.html",sharing = c("public"))
chart_link

情节确实包含下拉菜单,但它不起作用。更改下拉列表的值不会更改绘图本身。

有一个similar question,但按照它(仅)回答,我没有让下拉工作。(将df[k,]df[j,]放在列表中。所以如何使这些下降工作?任何帮助赞赏。

示例数据集是
 enter image description here
 它可以找到here

0 个答案:

没有答案