相关疑难解决方法(0)

如何使用DT,R和Shiny将图像嵌入到单元格中

如何在使用DT包生成的单元格中嵌入图像,以便使用闪亮的应用程序显示?

我的例子是基于这个问题R闪亮:我如何将本地图像放在闪亮的表格中

下面的示例代码不显示图像,而只显示网址.

# ui.R
require(shiny)
library(DT)

shinyUI(
  DT::dataTableOutput('mytable')
)

# Server.R
library(shiny)
library(DT)


dat <- data.frame(
  country = c('USA', 'China'),
  flag = c('<img src="test.png" height="52"></img>',
           '<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Flag_of_the_People%27s_Republic_of_China.svg/200px-Flag_of_the_People%27s_Republic_of_China.svg.png" height="52"></img>'
           )
)

shinyServer(function(input, output){
  output$mytable <- DT::renderDataTable({

    DT::datatable(dat)
  })
})
Run Code Online (Sandbox Code Playgroud)

r shiny shiny-server

12
推荐指数
1
解决办法
6264
查看次数

在图表弹出窗口中放置图表

我正在使用plotly for R,虽然我也习惯使用Python版本.当我将鼠标悬停在数据点上时,有没有办法让弹出窗口包含另一个图表?理想情况下,图表将根据数据创建,但我可以使用静态图像作为后备.

我不确定从哪里开始,并提前为没有MWE而道歉.

python plot r plotly

7
推荐指数
1
解决办法
2130
查看次数

将鼠标悬停在闪亮的App的R图表中

这里有人在将鼠标悬停在地块或任何可以这样做的包装上时显示图像的示例吗?我已经尝试了一些东西,但它只会显示url而不会显示图像。我知道这段代码只是封装了URL。如何建立一个div以显示图像。

library(shiny)
library(shinydashboard)
library(DT)
library(dplyr)
library(plotly)

# Data ------------------------------------------------------------------
dt <- data.frame(fruits = c("apple","banana","oranges"),
  rank = c(11, 22, 33), 
  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"
))

# img_dt <- dt %>%
#   mutate(img = paste0("<a target='_blank' href='", image_url, "'><img src=\'", image_url, "' height='40'></img></a>")) %>%
#   mutate(link = paste0("<a href='", image_url,"' target='_blank'>","View photo","</a>")) 

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

  dashboardSidebar(),

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

    plotlyOutput("hoverplot")
  )
)

server <- function(input, output) …
Run Code Online (Sandbox Code Playgroud)

r shiny plotly shinyapps r-plotly

5
推荐指数
1
解决办法
149
查看次数

标签 统计

r ×3

plotly ×2

shiny ×2

plot ×1

python ×1

r-plotly ×1

shiny-server ×1

shinyapps ×1