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

标签 javascript r google-maps-api-3 shiny rstudio

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

<!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>

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

ui.R

shinyUI(fluidPage(
  titlePanel("Google StreetView"),
  mainPanel(
    uiOutput("inc")
  )
))

服务器.R

library(shiny)

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

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

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

最佳答案

你可以用我的googleway来做到这一点包和有效的 Google map API key

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

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

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)

enter image description here

关于javascript - Shiny 应用程序内的 Google 街景容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30052837/

相关文章:

javascript - 如何从谷歌地图中的经度和纬度获取 place_id?

javascript - 获取 Google Maps API map 的宽度(以公里为单位)

java - 我如何在 google map api v3 中获取地点标记?

javascript - 在 Javascript 中将变量名转换为字符串?

R 在 for 循环中使用 tryCatch 将带有错误值的行添加到输出

javascript - 如何在 React Native/Redux 中使用推送路由为 NavigationStateUtils 创建唯一键?

r - 在 ggplot2 中,如何将刻度标签从绘图的底部移动到顶部?

重命名 Model.matrix 中的列名称

javascript - 使用正则表达式跨度包装 cout 的 "<<"的多次出现

javascript - 基于两个属性从 JavaScript 中的对象数组中获取唯一数组