如何从外部网站嵌入特定div到Rshiny Iframe

问题描述:

我想从外部网站嵌入表格,例如investing.com,但我发现难以嵌入特定的div,在当前示例中,汇率表具有id =cr1。我怎么只能嵌入表格本身?如何从外部网站嵌入特定div到Rshiny Iframe

rm(list = ls()) 
library(shiny) 

ui <- fluidPage(titlePanel("Getting A specific div from external website"), 
       mainPanel(fluidRow(     
        tags$iframe(seamless="seamless",src="http://www.investing.com/quotes/streaming-forex-rates-%E2%80%93-majors", height=600, width=1000) 
       ) 
     ) 
) 
server <- function(input, output) {} 
shinyApp(ui, server) 

我想表中仅红色

enter image description here

+0

这是什么语言?你用JavaScript标记了你的问题,但你的代码不是JavaScript。 –

+0

其R,我需要使用Javascript来执行该调用。我将删除不必要的标签 –

我觉得从隐藏的iframe的部分(AT-至少它似乎为我做的跨域策略块你)但你可以下载表格并显示它,

rm(list = ls()) 
library(shiny) 

ui <- shinyUI(fluidPage(
    tags$head(
    tags$script(
     HTML(
     ' 
     $(document).ready(function(){ 
     // Should work if not blocked 
     $("#myiframe").attr("src","http://www.investing.com/quotes/streaming-forex-rates-%E2%80%93-majors"); 

     $("#myiframe").load(function(){ 
      console.log("UPDATED"); 
      var iframe = $("#myiframe").contents(), 
      tbl = iframe.find("#cr1").clone(); 
      iframe.find("html").replaceWidth(tbl); 
     }); 
     }); 
     ' 
    ) 
    ) 
), 
    titlePanel("Getting A specific div from external website"), 
    mainPanel(fluidRow( 
     tags$iframe(id="myiframe",seamless="seamless",src="", height=600, width=1000), 
     dataTableOutput("tbl1") 
    ) 
) 
)) 

library(httr) 
library(XML) 
server <- shinyServer(function(input, output) { 
    url <- "http://www.investing.com/quotes/streaming-forex-rates-%E2%80%93-majors" 
    page.DOM <- content(GET(url)) 
    tables <- readHTMLTable(page.DOM) 
    exchng.tbl <- tables$cr1 

    # cr1 
    output$tbl1 <- renderDataTable({ 
    exchng.tbl 
    }) 

}) 
shinyApp(ui, server) 
+0

还需要在整个页面中 –

+0

页面底部至少有一个表格,当我运行Javascript时出现错误。检查[this](http://stackoverflow.com/questions/6170925/get-dom-content-of-cross-domain-iframe)链接。除非代理它,否则我认为不可能编辑iframe中的部分。 –