【问题标题】:How to fix the hoverinfo error in my shiny app?如何修复闪亮应用程序中的 hoverinfo 错误?
【发布时间】:2019-10-14 13:35:54
【问题描述】:

我使用 ggplot2 和 plotly 开发了一个闪亮的应用程序,但是,对于我添加为上限和下限的两条水平线,悬停文本没有正确显示。我想隐藏这两行的悬停文本。有人知道怎么实现吗?

我找到了一种解决方案,但它不适用于闪亮
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")})

 })

【问题讨论】:

    标签: r shiny ggplotly


    【解决方案1】:

    您可以将text 美学传递给ggplot 函数的aes,而不是使用style

    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)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-27
      • 2017-03-24
      • 2018-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2015-07-02
      相关资源
      最近更新 更多