1

Please check the snapshot below. I want to enter the url of any website in the search bar in the left box and the webpage can be displayed real time in the right box. The command "searchInput" I used is a shinyWidget and does not fulfill this. Please help me with a fix here. Also I would like to give a default web page link when the app runs like any site name. Please help me here.

library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- dashboardPage(
dashboardHeader(title = "Web Page"),
dashboardSidebar(
width = 0
),
dashboardBody(
box(title = "Web Page Search", status = "primary",height = "155" 
,solidHeader = T,
    uiOutput("search_plot")),
box( title = "Web Page", status = "primary", height = "618",solidHeader = T, 
     uiOutput("wep_page"))))
server <- function(input, output) 
{ 
output$search_plot <- renderUI({
searchInput(inputId = "Id009", 
          label = "Enter the address", 
          placeholder = "A placeholder", 
          btnSearch = icon("search"), 
          btnReset = icon("remove"), 
          width = "100%")
})
output$wep_page <- renderUI({
})
}
shinyApp(ui, server)
Adam Shaw
  • 519
  • 9
  • 24

1 Answers1

3

You could do something like this:

library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- dashboardPage(
  dashboardHeader(title = "Web Page"),
  dashboardSidebar(
    width = 0
  ),
  dashboardBody(
    box(title = "Web Page Search", status = "primary",height = "155" 
        ,solidHeader = T,
        uiOutput("search_plot")),
    box( title = "Web Page", status = "primary", height = "860px",solidHeader = T, 
         uiOutput("wep_page"))))
server <- function(input, output) 
{ 
  output$search_plot <- renderUI({
    searchInput(inputId = "Id009", 
                label = "Enter the address",
                btnSearch = icon("search"), 
                btnReset = icon("remove"), 
                value='https://',
                width = "100%")
  })
  output$wep_page <- renderUI({
    print(input$Id009)
    tags$iframe(src=input$Id009,width='100%',height='800px')
  })
}
shinyApp(ui, server)

enter image description here

Note that this may require some tweaking. i.e. check that the URL starts with http:// or https:// and probably some error handling, but this may help you in the right direction. Also, not all websites can be rendered in an iframe, for more info see here.

Florian
  • 24,425
  • 4
  • 49
  • 80
  • Thanks boss for replying, however I am not able to see web content in the right box. I tried google.com but it is not appearing, kindly help me. – Adam Shaw Jan 17 '18 at 08:25
  • Hi @Adam, I tried both `https://google.com` and `https://nos.nl`. The first one does not work, the second one does. See the top answer of the [link I posted](https://stackoverflow.com/questions/9158024/iframe-with-external-page-not-working). – Florian Jan 17 '18 at 08:27
  • sure, however if there is an issue with frame, can't we do it with simple tags$html? – Adam Shaw Jan 17 '18 at 08:34
  • Sorry, I wish I could help you with that, but as far as I know: No. – Florian Jan 17 '18 at 08:39
  • I need one little clarity here as I being new in the domain, from a lehman's perspective, do you mean to say that R shiny cannot open all the websites, right? – Adam Shaw Jan 17 '18 at 08:43
  • 1
    Yes indeed. As far as I know, any website that has a X-FRAME-OPTIONS HTTP header cannot be opened in Shiny. – Florian Jan 17 '18 at 08:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/163306/discussion-between-adam-shaw-and-florian). – Adam Shaw Jan 17 '18 at 08:47