Black Lives Matter. Please consider donating to Black Girls Code today.

How to add text in plotlyOutput?

Hi,

Consider the following example:

ui <- fluidPage(
tabsetPanel(
tabPanel(“Scatter Plot”,
mainPanel(plotlyOutput(“scatter”, height = “500px”))
) # End “Scatter Plot” tabPanel

) # End tabsetPanel
) # fluidPage

server <- function(input, output) {
output$scatter <- renderPlotly({
ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
ggplotly(ggiris)

# time  stamp
grid.text(paste("Shiny", Sys.time()), x = 0.85, y = 0.03, gp = gpar(fontsize = 10, col = "blue"))

}) ## output$scatter
}

shinyApp(ui = ui, server = server)

It throws the error:

Warning: Error in UseMethod: no applicable method for ‘plotly_build’ applied to an object of class “c(‘text’, ‘grob’, ‘gDesc’)”

I like to obtain an output similar to this:

Thank you very much for your help.