在if应用程序中嵌入iframe

时间:2015-10-08 15:54:46

标签: r iframe shiny

这是我的用户界面。 R

shinyUI(fluidPage(titlePanel("Getting Iframe"), 
              sidebarLayout(
                  sidebarPanel(
                      fluidRow(
                          column(6,
                                 selectInput("Member", label=h5("Choose a option"),
                                             choices=c('BCRA1','FITM2'))
                          ))),
                  mainPanel(fluidRow(
                      column(3, htmlOutput("frame"))
                  )
                  )
              )))

这是我的服务器.R

library(shiny)
members <- data.frame(name=c("Name 1", "Name 2"), nr=c('BCRA1','FITM2'))


shinyServer(function(input, output) {
loadframe <- reactive({ 
    validate(
        need(input$Member, "Member input is null!!")
    )
    query <- members[which(members$nr==input$Member),2]
    paste0("http://news.scibite.com/scibites/news.html?q=GENE$",query)
 })
 output$frame <- renderUI({
    tags$iframe(src=loadframe(), height=600, width=535)
   })
 })

我想从网页上获取iframe但是打印空白对此有任何帮助会不胜感激?

1 个答案:

答案 0 :(得分:18)

rm(list = ls())
library(shiny)
members <- data.frame(name=c("Name 1", "Name 2"), nr=c('BCRA1','FITM2'))

ui <- fluidPage(titlePanel("Getting Iframe"), 
                sidebarLayout(
                  sidebarPanel(
                    fluidRow(
                      column(6, selectInput("Member", label=h5("Choose a option"),choices=c('BCRA1','FITM2'))
                      ))),
                  mainPanel(fluidRow(
                    htmlOutput("frame")
                  )
                  )
                ))

server <- function(input, output) {
    observe({ 
    query <- members[which(members$nr==input$Member),2]
    test <<- paste0("http://news.scibite.com/scibites/news.html?q=GENE$",query)
  })
  output$frame <- renderUI({
    input$Member
    my_test <- tags$iframe(src=test, height=600, width=535)
    print(my_test)
    my_test
  })
}

shinyApp(ui, server)

enter image description here