embed iframe inside shiny app

2020-01-24 05:08发布

问题:

this is my UI. 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"))
                  )
                  )
              )))

This is my server.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)
   })
 })

I want to get the iframe from the web page but its printing blank any help on this would be appreciated ?

回答1:

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)



标签: r iframe shiny