首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在表中添加包含图像的弹出窗口

在表中添加包含图像的弹出窗口
EN

Stack Overflow用户
提问于 2018-09-29 20:04:06
回答 1查看 422关注 0票数 1

我有一个表,它显示与这些图像相对应的图像和度量。我想以较小的尺寸显示图像(所以表是紧凑的),然后使用popover功能将图像悬停在图像上,然后以更大的大小显示图像。

我找到了一种以小尺寸显示图像的方法(强制宽度为75 an ),但我无法找到一种在使用闪亮时添加带有图像的弹出窗口的方法。

有什么帮助吗?提前感谢!

下面是一个简化的表作为一个示例:

代码语言:javascript
复制
library(shiny)
library(shinydashboard)
library(DT)

# Data ------------------------------------------------------------------
dt <- data.frame(rank = c(1, 2, 3, 4, 5), 
             image_url = c('https://images.unsplash.com/photo-1521671413015-ce2b0103c8c7?ixlib=rb-0.3.5&s=45547f67f01ffdcad0e33c8417b840a9&auto=format&fit=crop&w=667&q=80', 
                           "https://images.unsplash.com/photo-1520699697851-3dc68aa3a474?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef15aee8bcb3f5928e5b31347adb6173&auto=format&fit=crop&w=400&q=80", 
                           "https://images.unsplash.com/photo-1501925873391-c3cd73416c5b?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=379e4a0fffc6d11cd5794806681d0211&auto=format&fit=crop&w=750&q=80", 
                           "https://images.unsplash.com/photo-1493019352063-500af484329e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f1e0ce442afdcaf2cdc4fde83012346e&auto=format&fit=crop&w=750&q=80", 
                           "https://images.unsplash.com/photo-1422056551295-3b38e8a20462?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=3eb1f67f2b9c1c26435fc584a0a1f75d&auto=format&fit=crop&w=667&q=80")
             )

img_dt <- dt %>%
  mutate(img = paste0("<img class = small-img src='", image_url, "'/>")) 

# Dashboard ----------------------------------------------------------------
ui <- dashboardPage(
  dashboardHeader(title = "Test"),

  dashboardSidebar(),

  dashboardBody(
    tags$head(
      tags$style(
        HTML(
        "img.small-img {
        max-width: 75px;
        }")
      )
    ),

    dataTableOutput("example_table")
    )
  )

server <- function(input, output) {
  output$example_table <- renderDataTable({
  img_dt}, 
  escape = FALSE)
  }

shinyApp(ui = ui, server = server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-30 21:06:21

这并不完全按照你的要求,但它增加了图片的大小悬停在它之上。所以这不是一个真正的弹出,只是一些css转换。

server.R

代码语言:javascript
复制
server <- function(input, output) {
  output$example_table <- renderDataTable({
    img_dt},
    escape = FALSE,
    callback=JS(
      'table.on("mouseover","tr", function() {
      $(".small-img").hover(function(){
          $(this).css("transform", "scale(3, 3)");
        }, function(){
              $(this).css("transform", "none");
        });
      })'    
    ))
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52572105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档