如何将 Dropbox 中的图片嵌入到闪亮中

安德斯

我正在构建一个闪亮的应用程序,我希望能够在其中显示动态选择的图片,而无需下载它们。我大部分时间都在使用 rdrop2。这是我所拥有的(缩短版)。

library(shiny)
library(shinydashboard)
library(rdrop2)
library(httr)

drop_auth(rdstoken = "token.rds")



ui <- dashboardPage(title = "digiHerb",
                    
                    dashboardHeader(),
                    
                    dashboardSidebar(),
                    
                    dashboardBody(
                      column(width=12,
                             
                      # print url (just for for troubleshooting, and the url is showing correctly)
                      box(width = NULL,
                          textOutput('path')),
                      
                      # Method 1
                      box(width = NULL,
                        htmlOutput("picture"))
                      
                      # Method 2 - iframe
                      ,
                      box(width=NULL,
                          uiOutput('myIFrame'))
                      
                      # Method 3
                      ,
                      box(width = NULL,
                        uiOutput("img"))
                      
                      #alternative method - fails with error 'cant find function GET'
                      #,
                      #box(width = NULL,
                      #    htmlOutput("includeHTML"))
                      ))
 
)
                    

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

# get a list of the images from dropbox - they areall shared publically
shared <- drop_list_shared_links(verbose = F)
l <- length(shared$links)
sharedBefore <- data.frame()
for(i in 1:l){
  sharedBefore[i,1] <- shared$links[[i]]$name
  sharedBefore[i,2] <- shared$links[[i]]$url
}
colnames(sharedBefore) <- c("names", "url")


# using just a static entry for now (first entry) - this will become dynamic
preview <- sharedBefore[1,"url"]

output$path <- renderText(print(preview))

# Method 1
output$picture<-renderText({
   c('<img src="',
     preview,
     '">')
 })
 
# Method 2 - iframe
output$myIFrame<-renderUI({
  tags$iframe(src = preview)
})

# Method 3:
output$img <- renderUI({
   tags$img(src =  preview, width="100%")
 })
   
# Alternative method 2:
#request <- httr::GET(url=preview)
#dropB <- httr::content(request, as="text")
#output$includeHTML <- renderText({
#  dropB
#})

 
 }

shinyApp(ui = ui, server = server)

有没有人对为什么这些方法都不起作用有任何建议?该应用程序托管在 Shinyapps.io 上并在其上进行测试。那里的日志显示没有错误。

编辑 10.08 :我找到了我认为的问题的根源。闪亮的应用程序在线显示这些小符号,图片应该在那里:在此处输入图片说明如果我右键单击它并按“在新选项卡中打开图像”,它会将我带到正确的图片。(实际上我更希望它带我去预览该图片的网址而不是实际图片,所以如果有人现在如何完成此操作,请分享。)如果我按检查然后查看控制台,我可以看到有一个错误,内容如下:

Refused to display 'https://www.dropbox.com/..........JPG?dl=0' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' ".

我似乎 Dropbox 不允许我“远程”查看图片或如何称呼它。所以我还没有解决这个问题——我仍然不知道如何解决这个问题。

安德斯

我似乎这是 dropbox 的一个已知问题,他们不允许使用 iframe。有一个称为嵌入器的新功能,据说可以做到这一点,但它相当复杂。请参阅此处的讨论:https : //www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Embed-dropbox-folder-in-the-a-webpage/td-p/72455也许我的最终解决方案是切换并使用谷歌驱动器或其他东西,但我会想念 rdrop2 包的功能。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章