15
votes

I have an URL which changes with an input on shiny app. I want to open an webpage and display that with in the tab panel of shiny window. Every time I change an input the webpage URL gets updated and I want to show that page in the same tab. As of now the web page opens in a separate window than the shiny window using browseURL function of R.

here is small test example for my case

ui.R

shinyUI(fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=1:5)
    ),
  mainPanel(
    htmlOutput("inc")
  )
))

server.R

shinyServer(function(input, output) {
  getPage<-function() {
    return((browseURL('http://www.google.com')))
  }
  output$inc<-renderUI({
    x <- input$test  
    getPage()
    })
})
1
Please provide a minimal reproducible example.jdharrison
i have included a code snippet of the same.hari

1 Answers

11
votes

Dont use browseURL. This explicitly opens the webpage in a new window.

library(shiny)
runApp(list(ui= fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=1:5)
  ),
  mainPanel(
    htmlOutput("inc")
  )
),
server = function(input, output) {
  getPage<-function() {
    return((HTML(readLines('http://www.google.com'))))
  }
  output$inc<-renderUI({
    x <- input$test  
    getPage()
  })
})
)

If you want to mirror the page you can use an iframe

library(shiny)
runApp(list(ui= fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=1:5)
  ),
  mainPanel(
    htmlOutput("inc")
  )
),
server = function(input, output) {
  getPage<-function() {
    return(tags$iframe(src = "http://www.bbc.co.uk"
                       , style="width:100%;",  frameborder="0"
                       ,id="iframe"
                       , height = "500px"))
  }
  output$inc<-renderUI({
    x <- input$test  
    getPage()
  })
})
)