Javascript 地图显示在外部浏览器中,但未显示在查看器窗格中
我对shiny和GoogleMapAPI都是新手。应用程序在外部模式下显示地图,但在窗口或查看器窗格中不显示地图。 ui.RJavascript 地图显示在外部浏览器中,但未显示在查看器窗格中,javascript,html,r,google-maps,shiny,Javascript,Html,R,Google Maps,Shiny,我对shiny和GoogleMapAPI都是新手。应用程序在外部模式下显示地图,但在窗口或查看器窗格中不显示地图。 ui.R library(shiny) shinyUI(fluidPage( # Application title titlePanel("My Map"), # Sidebar with a slider input for number of bins sidebarLayout( sidebarPanel( textInput("c
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("My Map"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textInput("coordinates","Coordinate"),
actionButton("updateMap", "Mark the Place")
),
# Show a plot of the generated distribution
mainPanel(
includeHTML("www/ui.html")
)
)
))
library(shiny)
shinyServer(function(input, output) {
observeEvent(input$updateMap, {
print(input$updateMap)
})
})
server.R
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("My Map"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textInput("coordinates","Coordinate"),
actionButton("updateMap", "Mark the Place")
),
# Show a plot of the generated distribution
mainPanel(
includeHTML("www/ui.html")
)
)
))
library(shiny)
shinyServer(function(input, output) {
observeEvent(input$updateMap, {
print(input$updateMap)
})
})
www目录中的ui.html
<!DOCTYPE html>
<html>
<head>
<style>
#map {
width: 500px;
height: 500px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
var map;
var counter = 0;
function placeddMarkers(lat = 44.5403, lng = -78.5463) {
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map,
icon: iconBase + 'schools_maps.png'
});
}
function initialize() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(mapCanvas, mapOptions)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<button onclick="placeddMarkers()">The time is?</button>
<div id="map"></div>
</body>
</html>
#地图{
宽度:500px;
高度:500px;
}
var映射;
var计数器=0;
功能位置标记(lat=44.5403,lng=-78.5463){
iconBase变量https://maps.google.com/mapfiles/kml/shapes/';
var marker=new google.maps.marker({
位置:新google.maps.LatLng(lat,lng),
地图:地图,
图标:iconBase+“schools\u maps.png”
});
}
函数初始化(){
var mapCanvas=document.getElementById('map');
变量映射选项={
中心:新google.maps.LatLng(44.5403,-78.5463),
缩放:8,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=新的google.maps.map(mapCanvas,mapOptions)
}
google.maps.event.addDomListener(窗口“加载”,初始化);
现在是什么时候?
从ui.html中删除placedMarkers定义后,一切似乎都正常工作。为什么会这样?问题出在闪亮还是我做错了什么。请帮忙