Shiny 应用程序内的 Google 街景容器

str*_*bes 2 javascript r google-maps-api-3 rstudio shiny

我一直在尝试使用 RStudio 的 Shiny 库创建一个嵌入 Google 街景的 Web 应用程序;但无法在应用程序中渲染街景。我一直在使用来自https://developers.google.com/maps/documentation/javascript/examples/streetview-embed的示例 JavaScript 和 HTML ,并将其粘贴到此处:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Street View containers</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
    <script>
function initialize() {
  var bryantPark = new google.maps.LatLng(37.869260, -122.254811);
  var panoramaOptions = {
    position: bryantPark,
    pov: {
      heading: 165,
      pitch: 0
    },
    zoom: 1
  };
  var myPano = new google.maps.StreetViewPanorama(
      document.getElementById('map-canvas'),
      panoramaOptions);
  myPano.setVisible(true);
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的用户界面和服务器脚本是:

ui.R

shinyUI(fluidPage(
  titlePanel("Google StreetView"),
  mainPanel(
    uiOutput("inc")
  )
))
Run Code Online (Sandbox Code Playgroud)

服务器R

library(shiny)

shinyServer(function(input, output) {
  getPage<-function() {
    return(includeHTML("googleStreetViewContainer.html"))
  }
  output$inc<-renderUI({getPage()})
})
Run Code Online (Sandbox Code Playgroud)

我尝试了几个不同版本的 ui.R 和 server.R 文件,方法是直接在 ui.R 文件中使用 includeHTML,而不是定义 getPage 函数,并在 ui.R 文件中使用tags$script。

我没有收到任何错误,但街景未渲染。有任何想法吗?

Sym*_*xAU 5

您可以使用我的googleway包和有效的 Google 地图 API 密钥来执行此操作

在 Shiny 中,您可以调用renderGoogle_map()servergoogle_mapOutput()UI加载绘图。

然后google_map()运行地图。当它打开时,您可以像往常一样在 Google 地图上访问卫星/街景

library(shiny)
library(shinydashboard)
library(googleway)

df <- data.frame(lat = -37.817714,
                lon = 144.967260,
                info = "Flinders Street Station")

map_key <- "your_api_key_here"

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box( google_mapOutput("myMap") )
  )
)


server <- function(input, output){

    output$myMap <- renderGoogle_map({
        google_map(location = c(df$lat, df$lon), key = map_key, search_box = T)
     })
}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述