闪亮/传单地图无法渲染

jos*_*453 5 r leaflet shiny

我无法在我的闪亮应用程序中获取传单地图,尽管代码本身在闪亮之外.我没有得到任何错误,所以我被困住,任何帮助表示赞赏.

样本数据:

cleanbuffalo <- data.frame(name = c("queen","toni","pepper"), 
                           longitude = c(31.8,32,33), 
                           latitude = c(-24,-25,-26))
Run Code Online (Sandbox Code Playgroud)

闪亮的用户界面:

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)
          )
        )
      )
  )
)
Run Code Online (Sandbox Code Playgroud)

闪亮的服务器:

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)
  })
Run Code Online (Sandbox Code Playgroud)

Mic*_*jka 7

由于heightleafletOutput 中的参数,它不起作用.奇怪的是,如果你在%地图中指定它没有显示,但如果你使用"px"(或一个将被强制转换为字符串并附加"px"的数字)它确实可以正常工作.

leafletOutput("map", width = "75%", height = "500px") 收益率:

在此输入图像描述

我不知道为什么会这样,但如果你想指定的高度leafletOutput%,你可以将它包装成一个div并给它适当的高度.


默认情况下,宽度设置为100%,高度设置为400px.因此,您不必指定这些参数 - 只有在我想要更改输出的大小时才会这样做.

leafletOutput(outputId, width = "100%", height = 400)
Run Code Online (Sandbox Code Playgroud)

  • `?shiny::plotOutput` 中的文档给出了原因:“请注意,对于高度,使用“auto”或“100%”通常不会按预期工作,因为高度是如何使用 HTML/CSS 计算的。” (2认同)