I want to show a mouse-over label when a user interacts with my plot, but in the script below, the label will disappear after a short while, even though the mouse is not moved:
library(shiny)
library(tidyverse)
ui <- basicPage(
plotOutput("plot1",
hover = "plot_hover"),
verbatimTextOutput("info")
)
server <- function(input, output) {
output$plot1 <- renderPlot({
hover_data <- nearPoints(mtcars, input$plot_hover) %>%
mutate(label = paste(mpg, cyl, disp, hp, sep = "\n"))
mtcars %>%
ggplot(aes(x = wt, y = mpg))+
geom_point()+
geom_label(data = hover_data, aes(label = label), nudge_x = 0.2)
})
output$info <- renderText({
paste0("x=", input$plot_hover$x, "\ny=", input$plot_hover$y)
})
}
shinyApp(ui, server)
I assume it is an issue with reactivity, but I fail to find the solution.
Any help will be greatly appreciated!