6

I am trying show a iframe with a website in shiny, but it is always showing blank page.

Below is the code taken from a different question

Code:

 rm(list = ls())
library(shiny)
members <- data.frame(name=c("Name 1", "Name 2"), nr=c('BCRA1','FITM2'))

ui <- fluidPage(titlePanel("Getting Iframe"), 

                  mainPanel(fluidRow(
                    htmlOutput("my_test")
                  )
                  )
                )

server <- function(input, output) {
  output$my_test <- renderUI({
     tags$iframe(src='https://www.google.co.in/', height=600, width=535)
  })
}

shinyApp(ui, server)

Output: enter image description here Why am I not able to show any website. Please help me, I google a lot and tried many options including the renderUI; htmloutput and uioutput panels.

surpavan
  • 1,372
  • 7
  • 34
  • 66
  • 2
    I can confirm that both your example or the example in the linked questions show a blank iframe. The javascript console gives me the error `Refused to display 'https://www.google.co.in/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.` in both cases. See [here](https://stackoverflow.com/questions/27358966/how-to-set-x-frame-options-on-iframe) for more reference. – Gregor de Cillia Apr 15 '18 at 14:31
  • Thank you @GregordeCillia - I checked a local web server and it working. Google is a common site tot check with in general so did not check other sites earlier. Please submit it as an answer - I will mark it complete; but R console did not throw it as an error. How can I know such cases? – surpavan Apr 15 '18 at 18:27
  • I just postet an answer and included a keyboard shortcut for acessing the JavaScript console. Quite a few error messages in JavaScript are not returned to R by shiny so I would suggest to check this console every now and then to keep your apps stable. – Gregor de Cillia Apr 15 '18 at 19:26

1 Answers1

3

So the problem you are facing is that the site you were referencing to had the X-Frame-Options set to sameorigin. This means that iframes are basically blocked by the https://www.google.co.in server.

You can see a corresponding error message in the javascript console which can be acessed with Ctrl+shift+K in google chrome. For other browsers see here.

Certain workarounds and morde discussion about the X-Frame-Options issue can be found in this question.

Gregor de Cillia
  • 7,397
  • 1
  • 26
  • 43