-1

I need to embed a webpage reached through a URL inputted by the user. I found this script but I can't make the iframe depend on a textInput() containing a URL. This example fails and I am not sure why.

library(shiny)

ui <- fluidPage(
  textInput('url','url',value = "www.google.com"),
  uiOutput('o')
)

server <- function(input, output, session) {
  
  output$o = renderUI({
    tags$iframe(src=input$url)
  })
  
}

shinyApp(ui, server)

1 Answer 1

1

You can do like this:

library(shiny)
ui <- fluidPage(titlePanel("Getting Iframe"), 
                sidebarLayout(
                  sidebarPanel(
                    textInput("url", label = "Enter url"), 
                    actionButton("go", "Go")
                  ),
                  mainPanel(
                    htmlOutput("frame")
                  )
                ))

server <- function(input, output) {
  output$frame <- renderUI({
    validate(need(input$go, message=FALSE))
    tags$iframe(src=isolate(input$url), height=600, width=535)
  })
}

shinyApp(ui, server)
2
  • 1
    I get a white iframe. I thought it was slow so i waited but nothing comes up. I get an error if i type "www.google.com". Instead get a white space with "google.com" Aug 27, 2017 at 6:12
  • Other websites work but Google doesn't seem to allow this. Sep 24, 2020 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.