简体   繁体   中英

Search Bar and Web page retrieval in R shiny box

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)

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)

在此输入图像描述

Note that this may require some tweaking. ie 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM