【问题标题】:Search Bar and Web page retrieval in R shiny boxR闪亮框中的搜索栏和网页检索
【发布时间】:2018-06-26 00:32:06
【问题描述】:

请检查下面的快照。我想在左框的搜索栏中输入任意网站的url,网页可以在右框中实时显示。我使用的命令“searchInput”是一个shinyWidget,并没有实现这一点。请在这里帮助我解决问题。当应用程序像任何站点名称一样运行时,我还想提供一个默认网页链接。请在这里帮助我。

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)

【问题讨论】:

    标签: r shiny shinydashboard shinyjs


    【解决方案1】:

    你可以这样做:

    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)
    

    请注意,这可能需要一些调整。即检查 URL 是否以 http:// 或 https:// 开头,并可能进行一些错误处理,但这可能会帮助您朝着正确的方向前进。此外,并非所有网站都可以在 iframe 中呈现,有关详细信息,请参阅 here。

    【讨论】:

    • 感谢老板回复,但是我在右边的框中看不到网页内容。我尝试了 google.com,但它没有出现,请帮助我。
    • 嗨@Adam,我尝试了https://google.com 和https://nos.nl。第一个不起作用,第二个起作用。请参阅link I posted 的最佳答案。
    • 当然,但是如果框架有问题,我们不能用简单的标签$html来解决吗?
    • 对不起,我希望我能帮助你,但据我所知:没有。
    • 确实如此。据我所知,任何具有 X-FRAME-OPTIONS HTTP 标头的网站都无法在 Shiny 中打开。
    猜你喜欢
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 2014-08-26
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 2020-04-11
    相关资源
    最近更新 更多