I am trying to embed Google Group into my a Shiny App. But it doesnt show up. What's going wrong?
library(shiny)
ui <- fluidPage(
titlePanel("Google Groups"),
htmlOutput("iframe")
)
server <- function(input, output) {
output$iframe <- renderUI({
src = "https://groups.google.com/forum/embed/?place=forum/shiny-discuss"
tags$iframe(src=src, height=400, width=600, frameborder='no')
})
}
shinyApp(ui, server)
OK. I figured it out myself. Important was to pass the parenturl correctly with JS. This seems to work.
library(shiny)
library(shinyjs)
jsCode = "shinyjs.getGG = function(){
src='https://groups.google.com/forum/embed/?place=forum/shiny-discuss' +
'&showsearch=true&showpopout=true&parenturl=' +
encodeURIComponent(window.location.href);
Shiny.setInputValue('ggroups_url',src);
}"
ui <- fluidPage(
useShinyjs(), # Include shinyjs
extendShinyjs(text=jsCode),
titlePanel("Google Groups"),
htmlOutput("iframe")
)
server <- function(input, output) {
output$iframe <- renderUI({
js$getGG()
src = input$ggroups_url
cat("src = ",src,"\n")
tags$iframe(id="forum_embed", src=src, height=600, width='100%', frameborder='no')
})
}
shinyApp(ui, server)
I found another solution without javascript but constructing the parenturl using the session$clientData. Here it is:
library(shiny)
ui <- fluidPage(
titlePanel("Google Groups"),
htmlOutput("iframe")
)
server <- function(input, output, session) {
output$iframe <- renderUI({
parenturl <- paste0(session$clientData$url_protocol,
"//",session$clientData$url_hostname,
":",session$clientData$url_port,
session$clientData$url_pathname)
src = paste0('https://groups.google.com/forum/embed/?place=forum/shiny-discuss',
'&showsearch=true&showpopout=true&parenturl=',parenturl)
cat("src = ",src,"\n")
tags$iframe(id="forum_embed", src=src, height=600, width='100%', frameborder='no')
})
}
shinyApp(ui, server)
system
Closed
4
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.