PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 30, 2022

[FIXED] How can you pass a url to an iframe via textInput() in r shiny?

 November 30, 2022     iframe, r, shiny     No comments   

Issue

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)

Solution

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)


Answered By - Stéphane Laurent
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing