如何将外部图像加载到Shiny [英] How to load external image to Shiny
问题描述
在我当前的项目中,我正在尝试使用 R
将图像加载到闪亮的仪表板
。代码段如下所示:
In my current project, I am trying to load images to shiny dashboard
using R
. The code snippet is as shown below:
dashboardBody(
hr(),
fluidRow(
column(6,align="center",imageOutput("ginger"))
)
)
)
server <- function(input, output) {
output$ginger <- renderImage({
return(list(
src = "images/ginger.jpg",
contentType = "image/jpeg",
width = 300,
height = 200,
alt = "Face"
))
}, deleteFile = FALSE)
基本上,它只是在闪亮仪表板上显示图像
。这里图像存储在本地机器中。现在,我想从谷歌驱动器或网络加载图像。我正在尝试从我的Google驱动器加载图片,并且网址是 https:// drive.google.com/file/d/0By6SOdXnt-LFaDhpMlg3b3FiTEU/view 。
Basically, it just display the image on the shiny dashboard
. Here the image is stored in the local machine. Now, I want to load image from google drive or from the web. I am trying to load the image from my google drive and URL is https://drive.google.com/file/d/0By6SOdXnt-LFaDhpMlg3b3FiTEU/view.
我无法弄清楚如何从谷歌驱动器或网页加载闪亮的图像以及如何在图像中添加标题? 我错过了什么吗?
推荐答案
这个答案很有启发性。这是一个准系统闪亮的
应用,带有外部图片调用,用于显示您在Google云端硬盘帐户中提到的图片。
This answer is instructive. Here's a barebones shiny
app with an external image call to display the image that you mention on your Google Drive account.
library(shiny)
# Define UI with external image call
ui <- fluidPage(
titlePanel("Look at the image below"),
sidebarLayout(sidebarPanel(),
mainPanel(htmlOutput("picture"))))
# Define server with information needed to hotlink image
server <- function(input, output) {
output$picture <-
renderText({
c(
'<img src="',
"http://drive.google.com/uc?export=view&id=0By6SOdXnt-LFaDhpMlg3b3FiTEU",
'">'
)
})
}
shinyApp(ui = ui, server = server)
这篇关于如何将外部图像加载到Shiny的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!