我一直在尝试使用 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)
关于javascript - Shiny 应用程序内的 Google 街景容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30052837/