R / d3heatmap / shiny - is there a way to embed images in d3 tooltip?

て烟熏妆下的殇ゞ 提交于 2020-01-13 05:29:25

问题


I'd like to embed images (rather than the default Row - Column - Value data) in the d3 tooltip when scrolling over a cell.

library(shiny)
library(d3heatmap)

ui <- shinyUI(fluidPage(

  titlePanel("Old Faithful Geyser Data"),
mainPanel(
  d3heatmapOutput("out")
)
  )
)

server <- shinyServer(function(input, output) {

  output$out <- renderD3heatmap({
   d3heatmap(x = mtcars,
          Colv = NULL,
          scale= "column",
          key = FALSE,
          yaxis_font_size = "10pt",
          xaxis_font_size = "10pt")
 })

})

shinyApp(ui = ui, server = server)

Default Tooltip

1981 Toyota Carona


回答1:


One way to do this is to encode your image in base64 and then pass a matrix of those images to d3heatmap(..., cellnote = )

    var tip = d3.tip()
    .attr('class', 'd3heatmap-tip')
    .html(function(d, i) {
        return ('<img src="' + d.label + '"/>');
    })


来源:https://stackoverflow.com/questions/40044089/r-d3heatmap-shiny-is-there-a-way-to-embed-images-in-d3-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!