簡體   English   中英

在表格中添加包含圖片的彈出框-閃亮

[英]Add popover containing image in a table - Shiny

我有一個表,顯示圖像和與這些圖像相對應的度量。 我想以較小的尺寸顯示圖像(因此表格緊湊),然后使用彈出功能將鼠標懸停在圖像上,然后以較大的尺寸顯示圖像。

我有辦法以較小的尺寸顯示圖像(將寬度強制為75像素),但是當使用閃亮時,我想不出一種為圖像添加彈出框的方法。

有什么幫助嗎? 提前致謝!

這是一個簡化的表格作為示例:

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)

這並不能完全滿足您的要求,但是可以通過將鼠標懸停在圖片上來增加圖片的大小。 因此,它不是真正的彈出窗口,只是一些CSS轉換。

服務器

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");
        });
      })'    
    ))
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM