【问题标题】:Display ggplot inside a DT Shiny Table Tooltip在 DT Shiny Table Tooltip 中显示 ggplot
【发布时间】:2021-06-25 20:03:58
【问题描述】:

我正在尝试在工具提示中显示一个绘图。我只希望当我悬停在 mpg 行上方时显示工具提示。我试图实现这样的目标:https://laustep.github.io/stlahblog/posts/DTqTips.html,但没能实现。下面是我要显示的情节的代表解决方案。

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 datatables


    【解决方案1】:

    不确定这是否是您要查找的内容,但一种选择是使用 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"
    )
    

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

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 2018-02-06
      • 2021-12-27
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      • 2023-01-25
      • 1970-01-01
      • 2021-05-09
      相关资源
      最近更新 更多