在 DT Shiny Table 工具提示中显示 ggplot

问题描述 投票:0回答:1

我正在尝试在工具提示内显示绘图。我只希望当我将鼠标悬停在 mpg 行上方时显示工具提示。 我试图实现这样的目标:https://laustep.github.io/stlahblog/posts/DTqTips.html,但效果不佳。下面是一个 reprex 解决方案,其中包含我想要显示的图。

library(shiny)
library(DT)
library(tidyverse)

shinyApp(
  ui = fluidPage(
    selectInput('cylSelect', choices = c(4,6,8), label ="Select the # of cylinders"),
    dataTableOutput('table'),
  ),
  
  server = function(server, input, output) {
    
    cars <- reactive({
      mtcars %>%
        filter(cyl == input$cylSelect) %>%
        group_by(am) %>%
        summarise(across(everything(), mean))
    })
    
    p <- renderPlot({ 
      cars() %>%
      ggplot(aes(x = am, y=mpg)) +
      geom_bar(stat = 'identity')
    })
    
    output$table <- renderDataTable({
      datatable(cars()

      )
    })
  }
)
r ggplot2 shiny dt
1个回答
0
投票

不确定这是否是您正在寻找的内容,但一种选择是使用 tippy 包来创建列标题。

library(shiny)
library(tippy)


tippy("Example Text", 
      tooltip = paste(img(src="http://tippy.john-coene.com/logo.png")),
      allowHTML = TRUE,
      placement = "bottom",
      theme = "light"
)

不过,它仅适用于静态图像,但您可以简单地保存输出图并在工具提示中引用它。

© www.soinside.com 2019 - 2024. All rights reserved.