关于r:Shiny / Leaflet地图未呈现

Shiny/Leaflet map not rendering

我无法获得要在闪亮的应用程序中呈现的Leaflet地图,尽管代码本身在闪亮的外部也可以工作。我没有收到任何错误,所以我被卡住了,我们将不胜感激。

样本数据:

1
2
3
cleanbuffalo <- data.frame(name = c("queen","toni","pepper"),
                           longitude = c(31.8,32,33),
                           latitude = c(-24,-25,-26))

闪亮的用户界面:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
vars <- c(
 "Pepper" ="pepper",
 "Queen" ="queen",
 "Toni" ="toni"
)

shinyUI(navbarPage("Buffalo Migration", id ="nav",

  tabPanel("Interactive Map",

div(class="outer",

    leafletOutput("map", width ="100%", height ="100%"),
    #Panel Selection
    absolutePanel(id ="controls", class ="panel panel-default", fixed = TRUE,
      draggable = TRUE, top = 60, left ="auto", right = 20, bottom ="auto",
      width = 330, height ="auto",

      h2("Buffalo Migration"),
      #Buffalo Group selection
      checkboxGroupInput(
       "checkGroup", label = h3("Select Buffalo to Follow"),
        choices = vars,
        selected = 1)
          )
        )
      )
  )
)

发光服务器:

1
2
3
4
5
6
7
8
9
10
library(shiny)
library(dplyr)
library(leaflet)
library(scales)
library(lattice)

shinyServer(function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>% addTiles() %>% setView(lng = 31.88, lat = -25.02, zoom=1)
  })

由于leafletOutput中的height参数,它不起作用。奇怪的是,如果您在%中指定了地图,则不会显示该地图,但是如果您使用" px"(或将被强制转换为字符串并附加" px"的数字),则可以正常工作。 >

leafletOutput("map", width ="75%", height ="500px")产生:

enter

1
leafletOutput(outputId, width ="100%", height = 400)