在闪亮的应用程序中,HTML/Javascript加载新页面而不是出现在应用程序中
我正在尝试将Google Trends图像嵌入到一个闪亮的应用程序中,我希望用户能够在闪亮的仪表板中动态地改变国家。主要问题是嵌入的javascript/html加载了一个新的选项卡,而不是出现在应用程序中。(当我在其中一个图像上单击“嵌入”时,会出现javascript/html代码) 当我将javascript/html文本直接包含在UI中时,它会在闪亮的应用程序中正确加载。当我尝试将javascript/html从服务器传递到UI时,它会加载新选项卡在闪亮的应用程序中,HTML/Javascript加载新页面而不是出现在应用程序中,javascript,html,r,shiny,Javascript,Html,R,Shiny,我正在尝试将Google Trends图像嵌入到一个闪亮的应用程序中,我希望用户能够在闪亮的仪表板中动态地改变国家。主要问题是嵌入的javascript/html加载了一个新的选项卡,而不是出现在应用程序中。(当我在其中一个图像上单击“嵌入”时,会出现javascript/html代码) 当我将javascript/html文本直接包含在UI中时,它会在闪亮的应用程序中正确加载。当我尝试将javascript/html从服务器传递到UI时,它会加载新选项卡 ui尝试将其直接嵌入div以避免文档覆
ui尝试将其直接嵌入div
以避免文档覆盖。该函数称为renderesplowedgeto
。您需要添加一些JavaScript来选择所需的div
,并将div
添加到您的UI中。此外,我使用的脚本每次调用时都会清除上一个图表:
library(shiny)
ui <- fluidPage(
h1("Test App"),
fluidRow(
column(4, align = "center", offset = 4,
selectInput("choose_country",
"Choose Country",
choice = c("", "US", "NZ"),
selected = ""),
## this wrapper div is where the iframe will get embedded
tags$div(id="wrapper"),
uiOutput("html_out"),
)
)
)
server <- (function(input, output, session) {
output$html_out <- renderUI({
geo <- input$choose_country
tags$body(HTML(paste0('<script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/2213_RC01/embed_loader.js"></script> <script type="text/javascript"> var divElem = document.getElementById("wrapper"); document.getElementById("wrapper").innerHTML = ""; trends.embed.renderExploreWidgetTo(divElem, "TIMESERIES", {"comparisonItem":[{"keyword":"r shiny","geo":"',geo,'","time":"today 12-m"}],"category":0,"property":""}, {"exploreQuery":"q=r%20shiny&geo=',geo,'&date=today 12-m","guestPath":"https://trends.google.com:443/trends/embed/"}); </script>')))
})
})
shinyApp(ui, server)
库(闪亮)
用户界面