The example shiny app below shows a ggplot in which you can click anywhere within the plot area and see the text annotation "you clicked here" pop up on that coordinate. However, the text disappears almost instantly after showing up. How can I prevent it from disappearing until a new input (i.e., mouse click) comes in?
library(shiny)
library(ggplot2)
ui <- fluidPage(
plotOutput("example_plot", click = "mouse_click")
)
server <- function(input, output) {
output$example_plot <- renderPlot({
ggplot(mtcars, mapping = aes(x = disp, y = hp)) +
geom_point() +
annotate(geom = "text",
x = input$mouse_click$x,
y = input$mouse_click$y,
label = "you clicked here")
})
}
shinyApp(ui = ui, server = server)