2

I have developed a shiny app using ggplot2 and plotly, however, the hover text was not correctly showed for two horizontal lines which I added as the upper and lower limits. I want to hide the hover text for these two lines. Does anyone know how to achieve it?

I found one solution but it didn't work for shiny
Disable hover information for a specific layer (geom) of plotly

  library(shiny)
    shinyServer(

     function(input,output,session){
       reactivelab <- reactive({
           gg <-labn %>% filter(PARCAT2  == input$Group & LBTEST == 
                 input$Par & SUBJID == input$ID) })    

 output$labpot <- renderPlotly({
     req(nrow(reactivelab()) > 0)
     q <- ggplot(data=reactivelab(),aes(x=ADY, y=AVAL))+
        geom_point()+geom_line()+
        geom_hline(aes(yintercept=ANRLO),linetype="longdash")+
        geom_hline(aes(yintercept=ANRHI),linetype="longdash")+
        ylab("Lab Standard Value") + xlab("Lab Test Day") 
        mm <- style(q,  text =  paste("Lab Parameter:", reactivelab()$PARAM,
                                "<br>Lab Test Day:", reactivelab()$ADY,
                                "<br>Lab Standard Value:", reactivelab()$AVAL,
                                "<br>Normal Range Upper Limit:", reactivelab()$ANRHI,
                                "<br>Normal Range Lower Limit:", reactivelab()$ANRLO

  ), hoverinfo = "text")})

 })

Shiny App 1

Shiny App 2

Shree
  • 10,835
  • 1
  • 14
  • 36
clarkchen
  • 21
  • 2

1 Answers1

0

Instead of using style, you can pass the text aesthetic to the aes of the ggplot function:

ggplot(data=reactivelab(), 
       aes(x=ADY, y=AVAL, 
           text = paste("Lab Parameter:", PARAM,
                        "<br>Lab Test Day:", ADY,
                        "<br>Lab Standard Value:", AVAL,
                        "<br>Normal Range Upper Limit:", ANRHI,
                        "<br>Normal Range Lower Limit:", ANRLO)))
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225