R Plotly Deselect trace by default

帅比萌擦擦* 提交于 2019-12-30 06:47:42

问题


I am ussing R Plotly and have a line of the form:

add_trace(y = meanRank,
          x = DateOnly,
          data = timeSeriesDF,
          name = "Daily Value",
          text = hoverText,
          hoverinfo = "text",
          showlegend = TRUE)

It works fine. However, I want this trace to be "unselected" when the plot is shown. So a user would click it on the legend to show the line. I can't seem to find the parameter to show that.


回答1:


You could add visible = "legendonly":

library(plotly)
economics %>%
 transform(rate = unemploy / pop) %>%
 plot_ly(x = date, y = rate) %>%
 loess(rate ~ as.numeric(date), data = .) %>%
 broom::augment() %>%
 add_trace(y = .fitted, name = "foo", visible = "legendonly")

See the reference.




回答2:


you can use the attribute 'visible = legendonly' to other add_ functions such as:

add_lines(x = as.Date(x()$ds),
          y = round(y()$total),
          name = 'Inventory Total',
          visible = 'legendonly')


来源:https://stackoverflow.com/questions/39625910/r-plotly-deselect-trace-by-default

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!