Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opening webpages within shiny window without opening a separate window

Tags:

r

shiny

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()
    })
})
like image 687
hari Avatar asked Sep 12 '14 06:09

hari


1 Answers

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()
  })
})
)
like image 89
jdharrison Avatar answered Nov 10 '22 11:11

jdharrison