If you simply need to add text, add a custom button that triggers either a relayout or restyle event.
library(plotly)
x <- seq(-2*pi, 2*pi, length.out = 1000)
df <- data.frame(x, y = sin(x))
p <- plot_ly(df, x = ~x) %>%
add_lines(y = ~y)
faq_txt <- list(
x = 0,
y = 0,
text = "Sin starts at 0!"
)
layout(
p,
updatemenus = list(
list(
type = "buttons",
y = 0.8,
buttons = list(
list(
method = "relayout",
args = list("annotations", list(faq_txt)),
label = "FAQ"
)
)
)
)
)
Having a single button that adds and clears the same text isn't as straightforward. If you're willing to have another button to clear the text, you could add another to this example pretty easily, but for a better user experience, I think you'd have to write some custom HTML/JavaScript or move to a shiny app.