我正在尝试在工具提示内显示绘图。我只希望当我将鼠标悬停在 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()
)
})
}
)
不确定这是否是您正在寻找的内容,但一种选择是使用 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"
)
不过,它仅适用于静态图像,但您可以简单地保存输出图并在工具提示中引用它。