Shiny应用程序中的Google街景视图容器 [英] Google Street View container inside Shiny Application

查看:160
本文介绍了Shiny应用程序中的Google街景视图容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用RStudio的Shiny库创建嵌入式Google街景视图的Web应用程序;但一直没有能够获得适用于渲染的街景。
我一直使用以下示例中的JavaScript和HTML:


I have been trying to create a web application with an embedded Google Street View using RStudio's Shiny library; but have not been able to get the street view to render in the applicaiton. I've been using the example JavaScript and HTML from: https://developers.google.com/maps/documentation/javascript/examples/streetview-embed which I paste here:

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

My ui and server scripts are:

ui.R

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

and

server.R

library(shiny)

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

I've tried a few different versions of the ui.R and server.R files by using includeHTML directly in the ui.R file rather than defining the getPage function and also using tags$script in the ui.R file.

I have not gotten any errors, but the Street View is not rendering. Any ideas?

解决方案

You can do this with my googleway package and a valid Google Maps API key

In Shiny you call renderGoogle_map() in the server, and google_mapOutput() in the UI to load the plot.

Then google_map() to run the map. When it's open you can access satellite / streetview as per usual on a 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)

这篇关于Shiny应用程序中的Google街景视图容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆